Part Number Hot Search : 
SY100S HA17901A SP9600BN ICL765 SC241 MB158 PHL2143 PMEG2020
Product Description
Full Text Search
 

To Download PIC18F8680T-EPT Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2004 microchip technology inc. ds30491c pic18f6585/8585/6680/8680 data sheet 64/68/80-pin high-performance, 64-kbyte enhanced flash microcontrollers with ecan module
ds30491c-page ii ? 2004 microchip technology inc. information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. no representation or warranty is given and no liability is assumed by microchip technol ogy incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. use of mi crochip?s products as critical components in life support syst ems is not authorized except with express written approval by microchip. no licenses are conveyed, implicitly or ot herwise, under any intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , mplab, pic, picmicro, picstart, pro mate, powersmart and rfpic are registered trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. amplab, filterlab, micro id , mxdev, mxlab, picmaster, seeval, smartshunt and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. application maestro, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, migratable memory, mpasm, mplib, mplink, mpsim, pickit, picdem, picdem.net, pictail, powercal, powerinfo, powermate, powertool, rflab, select mode, smartsensor, smarttel and total endurance are trademarks of microchip technology incor porated in the u.s.a. and other countries. serialized quick turn programming (sqtp) is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2004, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices:  microchip products meet the specification cont ained in their particular microchip data sheet.  microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip's data sheets. most likely, the person doing so is engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semicondu ctor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are comm itted to continuously improving t he code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona and mountain view, california in october 2003. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2004 microchip technology inc. ds30491c-page 1 pic18f6585/8585/6680/8680 high-performance risc cpu:  source code compatible with the pic16 and pic17 instruction sets  linear program memory addressing to 2 mbytes  linear data memory addressing to 4096 bytes  1 kbyte of data eeprom  up to 10 mips operation: - dc ? 40 mhz osc./clock input - 4 mhz-10 mhz osc./clock input with pll active  16-bit wide instructions, 8-bit wide data path  priority levels for interrupts  31-level, software accessible hardware stack  8 x 8 single-cycle hardware multiplier external memory interface (pic18f8x8x devices only):  address capability of up to 2 mbytes  16-bit interface peripheral features:  high current sink/source 25 ma/25 ma  four external interrupt pins  timer0 module: 8-bit/16-bit timer/counter  timer1 module: 16-bit timer/counter  timer2 module: 8-bit timer/counter  timer3 module: 16-bit timer/counter  secondary oscillator clock option ? timer1/timer3  one capture/compare/pwm (ccp) module: - capture is 16-bit, max. resolution 6.25 ns (t cy /16) - compare is 16-bit, max. resolution 100 ns (t cy ) - pwm output: pwm resolution is 1 to 10-bit  enhanced capture/compare/pwm (eccp) module: - same capture/compare features as ccp - one, two or four pwm outputs - selectable polarity - programmable dead time - auto-shutdown on external event - auto-restart  master synchronous serial port (mssp) module with two modes of operation: - 3-wire spi? (supports all 4 spi modes) -i 2 c? master and slave mode  enhanced addressable usart module: - supports rs-232, rs-485 and lin 1.2 - programmable wake-up on start bit - auto-baud detect  parallel slave port (psp) module analog features:  up to 16-channel, 10-bit analog-to-digital converter module (a/d) with: - fast sampling rate - programmable acquisition time - conversion available during sleep  programmable 16-level low-voltage detection (lvd) module: - supports interrupt on low-voltage detection  programmable brown-out reset (bor)  dual analog comparators: - programmable input/output configuration ecan module features:  message bit rates up to 1 mbps  conforms to can 2.0b active specification  fully backward compatible with pic18xxx8 can modules  three modes of operation: - legacy, enhanced legacy, fifo  three dedicated transmit buffers with prioritization  two dedicated receive buffers  six programmable receive/transmit buffers  three full 29-bit acceptance masks  16 full 29-bit acceptance filters with dynamic association  devicenet? data byte filter support  automatic remote frame handling  advanced error management features special microcontroller features:  100,000 erase/write cycle enhanced flash program memory typical  1,000,000 erase/write cycle data eeprom memory typical  1-second programming time  flash/data eeprom retention: > 40 years  self-reprogrammable under software control  power-on reset (por), power-up timer (pwrt) and oscillator start-up timer (ost)  watchdog timer (wdt) with its own on-chip rc oscillator  programmable code protection  power saving sleep mode  selectable oscillator options including: - software enabled 4x phase lock loop (of primary oscillator) - secondary oscillator (32 khz) clock input  in-circuit serial programming? (icsp?) via two pins  mplab ? in-circuit debug (icd) via two pins 64/68/80-pin high-performance , 64-kbyte enhanced flash microcontrollers with ecan module
pic18f6585/8585/6680/8680 ds30491c-page 2 ? 2004 microchip technology inc. cmos technology:  low-power, high-speed flash technology  fully static design  wide operating voltage range (2.0v to 5.5v)  industrial and extended temperature ranges device program memory data memory i/o 10-bit a/d (ch) ccp/ eccp (pwm) mssp ecan/ ausart timers 8-bit/16-bit ema bytes # single-word instructions sram (bytes) eeprom (bytes) spi master i 2 c pic18f6585 48k 24576 3328 1024 53 12 1/1 y y y/y 2/3 n pic18f6680 64k 32768 3328 1024 53 12 1/1 y y y/y 2/3 n pic18f8585 48k 24576 3328 1024 69 16 1/1 y y y/y 2/3 y pic18f8680 64k 32768 3328 1024 69 16 1/1 y y y/y 2/3 y
? 2004 microchip technology inc. ds30491c-page 3 pic18f6585/8585/6680/8680 pin diagrams pic18f6x8x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 38 37 36 35 34 33 50 49 17 18 19 20 21 22 23 24 25 26 re2/cs re3 re4 re5/p1c re6/p1b re7/ccp2 (1) rd0/psp0 v dd v ss rd1/psp1 rd2/psp2 rd3/psp3 rd4/psp4 rd5/psp5 rd6/psp6 rd7/psp7 re1/wr re0/rd rg0/cantx1 rg1/cantx2 rg2/canrx rg3 rg5/mclr /v pp rg4/p1d v ss v dd rf7/ss rf6/an11/c1in- rf5/an10/c1in+/cv ref rf4/an9/c2in- rf3/an8/c2in+ rf2/an7/c1out rb0/int0 rb1/int1 rb2/int2 rb3/int3 rb4/kbi0 rb5/kbi1/pgm rb6/kbi2/pgc v ss osc2/clko/ra6 osc1/clki v dd rb7/kbi3/pgd rc4/sdi/sda rc3/sck/scl rc2/ccp1/p1a rf0/an5 rf1/an6/c2out av dd av ss ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 v ss v dd ra4/t0cki ra5/an4/lvdin rc1/t1osi/ccp2 (1) rc0/t1oso/t13cki rc7/rx/dt rc6/tx/ck rc5/sdo 15 16 31 40 39 27 28 29 30 32 48 47 46 45 44 43 42 41 54 53 52 51 58 57 56 55 60 59 64 63 62 61 64-pin tqfp note 1: ccp2 pin placement depends on ccp2mx setting.
pic18f6585/8585/6680/8680 ds30491c-page 4 ? 2004 microchip technology inc. pin diagrams (continued) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 9 8 7 6 5 4 3 2 1 6867666564636261 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 top view rb0/int0 rb1/int1 rb2/int2 rb3/int3 rb4/kbi0 rb5/kbi1/pgm rb6/kbi2/pgc v ss osc2/clko/ra6 osc1/clki v dd rb7/kbi3/pgd rc4/sdi/sda rc3/sck/scl rc2/ccp1/p1a re1/wr re0/rd rg0/cantx1 rg1/cantx2 rg2/canrx rg3 rg5/mclr /v pp rg4/p1d v ss v dd rf7/ss rf6/an11/c1in- rf5/an10/c1in+/cv ref rf4/an9/c2in- rf3/an8/c2in+ rf2/an7/c1out re2/cs re3 re4 re5/p1c re6/p1b re7/ccp2 (1) rd0/psp0 v dd v ss rd1/psp1 rd2/psp2 rd3/psp3 rd4/psp4 rd5/psp5 rd6/psp6 rd7/psp7 rf1/an6/c2out rf0/an5 av dd av ss ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 v dd ra4/t0cki ra5/an4/lvdin rc1/t1osi/ccp2 (1) rc0/t1oso/t13cki rc7/rx/dt rc6/tx/ck rc5/sdo n/c n/c n/c n/c v ss pic18f6x8x 68-pin plcc note 1: ccp2 pin placement depends on ccp2mx setting.
? 2004 microchip technology inc. ds30491c-page 5 pic18f6585/8585/6680/8680 pin diagrams (continued) pic18f8x8x 3 4 5 6 7 8 9 10 11 12 13 14 15 16 48 47 46 45 44 43 42 41 40 39 64 63 62 61 21 22 23 24 25 26 27 28 29 30 31 32 re2/cs /ad10 re3/ad11 re4/ad12 re5/ad13/p1c (3) re6/ad14/p1b (3) re7/ccp2 (2) /ad15 rd0/psp0 (1) /ad0 v dd v ss rd1/psp1 (1) /ad1 rd2/psp2 (1) /ad2 rd3/psp3 (1) /ad3 rd4/psp4 (1) /ad4 rd5/psp5 (1) /ad5 rd6/psp6 (1) /ad6 rd7/psp7 (1) /ad7 re1/wr /ad9 re0/rd /ad8 rg0/cantx1 rg1/cantx2 rg2/canrx rg3 rg5/mclr /v pp rg4/p1d v ss v dd rf7/ss rb0/int0 rb1/int1 rb2/int2 rb3/int3/ccp2 (2) rb4/kbi0 rb5/kbi1/pgm rb6/kbi2/pgc v ss osc2/clko/ra6 osc1/clki v dd rb7/kbi3/pgd rc4/sdi/sda rc3/sck/scl rc2/ccp1/p1a rf0/an5 rf1/an6/c2out av dd av ss ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 v ss v dd ra4/t0cki ra5/an4/lvdin rc1/t1osi/ccp2 (2) rc0/t1oso/t13cki rc7/rx/dt rc6/tx/ck rc5/sdo rj0/ale rj1/oe rh1/a17 rh0/a16 1 2 rh2/a18 rh3/a19 17 18 rh7/an15/p1b (3) rh6/an14/p1c (3) rh5/an13 rh4/an12 rj5/ce rj4/ba0 37 rj7/ub rj6/lb 50 49 rj2/wrl rj3/wrh 19 20 33 34 35 36 38 58 57 56 55 54 53 52 51 60 59 68 67 66 65 72 71 70 69 74 73 78 77 76 75 79 80 80-pin tqfp note 1: psp is available only in microcontroller mode. 2: ccp2 pin placement depends on ccp2mx and processor mode settings. 3: p1b and p1c pin placement depends on eccpmx setting. rf5/an10/c1in+/cv ref rf4/an9/c2in- rf3/an8/c2in+ rf2/an7/c1out rf6/an11/c1in-
pic18f6585/8585/6680/8680 ds30491c-page 6 ? 2004 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 9 2.0 oscillator configurations ................................................................................................... ......................................................... 23 3.0 reset ....................................................................................................................... ................................................................... 33 4.0 memory organization ......................................................................................................... ........................................................ 51 5.0 flash program memory........................................................................................................ ...................................................... 83 6.0 external memory interface ................................................................................................... ...................................................... 93 7.0 data eeprom memory .......................................................................................................... ................................................. 101 8.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 107 9.0 interrupts .................................................................................................................. ................................................................ 109 10.0 i/o ports .................................................................................................................. ................................................................. 125 11.0 timer0 module .............................................................................................................. ........................................................... 155 12.0 timer1 module .............................................................................................................. ........................................................... 159 13.0 timer2 module .............................................................................................................. ........................................................... 162 14.0 timer3 module .............................................................................................................. ........................................................... 164 15.0 capture/compare/pwm (ccp) modules .......................................................................................... ....................................... 167 16.0 enhanced capture/compare/pwm (eccp) module................................................................................. ............................... 175 17.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 189 18.0 enhanced universal synchronous asynchronous receiver transmitter (usart)................................................... ............... 229 19.0 10-bit analog-to-digital converter (a/d) module ............................................................................ .......................................... 249 20.0 comparator module.......................................................................................................... ........................................................ 259 21.0 comparator voltage reference module ........................................................................................ ........................................... 265 22.0 low-voltage detect ......................................................................................................... ......................................................... 269 23.0 ecan module................................................................................................................ ........................................................... 275 24.0 special features of the cpu ................................................................................................ .................................................... 345 25.0 instruction set summary .................................................................................................... ...................................................... 365 26.0 development support........................................................................................................ ....................................................... 407 27.0 electrical characteristics ................................................................................................. ......................................................... 413 28.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 449 29.0 packaging information...................................................................................................... ........................................................ 465 appendix a: revision history................................................................................................... .......................................................... 469 appendix b: device differences................................................................................................. ........................................................ 469 appendix c: conversion considerations .......................................................................................... ................................................. 470 appendix d: migration from mid-range to enhanced devices ....................................................................... ................................... 470 appendix e: migration from high-end to enhanced devices........................................................................ ..................................... 471 index .......................................................................................................................... ........................................................................ 473 on-line support................................................................................................................ ................................................................. 487 systems information and upgrade hot line ....................................................................................... ............................................... 487 reader response ................................................................................................................ .............................................................. 488 pic18f6585/8585/6680/8680 product identification system ........................................................................ .................................... 489
? 2004 microchip technology inc. ds30491c-page 7 pic18f6585/8585/6680/8680 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@mail.microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following:  microchip?s worldwide web site; http://www.microchip.com  your local microchip sales office (see last page)  the microchip corporate literature center; u.s. fax: (480) 792-7277 when contacting a sales office or the literature center, pleas e specify which device, revisi on of silicon and data sheet (inclu de liter- ature number) you are using. customer notification system register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
pic18f6585/8585/6680/8680 ds30491c-page 8 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 9 pic18f6585/8585/6680/8680 1.0 device overview this document contains device specific information for the following devices: pic18f6x8x devices are available in 64-pin tqfp and 68-pin plcc packages. pic18f8x8x devices are available in the 80-pin tqfp package. they are differentiated from each other in four ways: 1. flash program memory (48 kbytes for pic18fx585 devices, 64 kbytes for pic18fx680) 2. a/d channels (12 for pic18f6x8x devices, 16 for pic18f8x8x) 3. i/o ports (7 on pic18f6x8x devices, 9 on pic18f8x8x) 4. external program memory interface (present only on pic18f8x8x devices) all other features for devices in the pic18f6585/8585/6680/8680 family are identical. these are summarized in table 1-1. block diagrams of the pic18f6x8x and pic18f8x8x devices are provided in figure 1-1 and figure 1-2, respectively. the pinouts for these device families are listed in table 1-2. table 1-1: pic18f6585/8585/6680/8680 device features  pic18f6585  pic18f8585  pic18f6680  pic18f8680 features pic18f6585 pic18f6680 pic18f8585 pic18f8680 operating frequency dc ? 40 mhz dc ? 40 mhz dc ? 40 mhz dc?25mhzw/ema dc?40mhz dc ? 25 mhz w/ema program memory (bytes) 48k 64k 48k (2 mb ema) 64k (2 mb ema) program memory (instructions) 24576 32768 24576 32768 data memory (bytes) 3328 3328 3328 3328 data eeprom memory (bytes) 1024 1024 1024 1024 external memory interface no no yes yes interrupt sources 29 29 29 29 i/o ports ports a - g ports a - gports a - h, j ports a - h, j timers 4 4 4 4 capture/compare/pwm module 1 1 1 1 enhanced capture/compare/pwm module 11 1 1 serial communications mssp, enhanced ausart, ecan mssp, enhanced ausart, ecan mssp, enhanced ausart, ecan mssp, enhanced ausart, ecan parallel communications psp psp psp (1) psp (1) 10-bit analog-to-digital module 12 input channels 12 input channels 16 input channels 16 input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow (pwrt, ost) por, bor, reset instruction, stack full, stack underflow (pwrt, ost) por, bor, reset instruction, stack full, stack underflow (pwrt, ost) por, bor, reset instruction, stack full, stack underflow (pwrt, ost) programmable low-voltage detect yes yes yes yes programmable brown-out reset yes yes yes yes instruction set 75 instructions 75 instructions 75 instructions 75 instructions package 64-pin tqfp, 68-pin plcc 64-pin tqfp, 68-pin plcc 80-pin tqfp 80-pin tqfp note 1: psp is only available in microcontroller mode.
pic18f6585/8585/6680/8680 ds30491c-page 10 ? 2004 microchip technology inc. figure 1-1: pic18f6x8x blo ck diagram power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control osc1/clki osc2/clko/ra6 rg5/ v dd , v ss porta portb portc ra4/t0cki ra5/an4/lvdin rb2/int2:rb0/int0 rb6/kbi2/pgc rc0/t1oso/t13cki rc1/t1osi/ccp2 (1) rc2/ccp1/p1a rc3/sck/scl rc4/sdi/sda rc5/sdo rc6/tx/ck rc7/rx/dt brown-out reset ausart comparator synchronous bor timer1 timer2 serial port ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 ecan module timing generation 10-bit adc rb3/int3 data latch data ram (3328 bytes) address latch address<12> 12 bank0, f bsr fsr0 fsr1 fsr2 inc/dec logic decode 4 12 4 pch pcl pclath 8 31 level stack program counter prodl prodh 8 x 8 multiply w 8 bitop 8 8 alu<8> 8 te s t m o d e select address latch program memory (48 kbytes) data latch 21 21 16 8 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 rom latch timer3 portd rd7/psp7 ccp2 rb4/kbi0 rb5/kbi1/pgm pclatu pcu precision reference band gap porte portg rg0/cantx1 rg1/cantx2 rg2/canrx rg3 rg4/p1d timer0 re6/p1b re7/ccp2 (1) re5/p1c re4 re3 re2/cs re0/rd re1/wr lvd eccp1 rb7/kbi3/pgd :rd0/psp0 rf6/an11/c1in- rf7/ss rf5/an10/c1in+/cv ref rf4/an9/c2in- rf3/an8/c2in+ rf2/an7/c1out rf0/an5 rf1/an6/c2out portf rg5/mclr /v pp mclr osc2/clko/ra6 data eeprom note 1: the ccp2 pin placement depends on the ccp2mx and processor mode settings.
? 2004 microchip technology inc. ds30491c-page 11 pic18f6585/8585/6680/8680 figure 1-2: pic18f8x8x block diagram power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control osc1/clki osc2/clko/ra6 rg5/ v dd , v ss porta portb portc ra4/t0cki ra5/an4/lvdin rb2/int2:rb0/int0 rb6/kbi2/pgc rc0/t1oso/t13cki rc1/t1osi/ccp2 (1) rc2/ccp1/p1a rc3/sck/scl rc4/sdi/sda rc5/sdo rc6/tx/ck rc7/rx/dt brown-out reset ausart comparator synchronous bor timer1 timer2 serial port ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 ecan module timing generation 10-bit adc rb3/int3/ccp2 (1) data latch data ram (3328 bytes) address latch address<12> 12 bank0, f bsr fsr0 fsr1 fsr2 inc/dec logic decode 4 12 4 pch pcl pclath 8 31 level stack program counter prodl prodh 8 x 8 multiply w 8 bitop 8 8 alu<8> 8 test mode select address latch program memory (64 kbytes) data latch 21 21 16 8 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 rom latch timer3 portd rd7/psp7 ccp2 rb4/kbi0 rb5/kbi1/pgm pclatu pcu precision reference band gap porte portg rg0/cantx1 rg1/cantx2 rg2/canrx rg3 rg4/p1d timer0 re6/ad14/p1b (2) re7/ccp2 (1) /ad15 re5/ad13/p1c (2) re4/ad12 re3/ad11 re2/cs /ad10 re0/rd /ad8 re1/wr /ad9 lvd eccp1 rb7/kbi3/pgd /ad7: rf6/an11/c1in- rf7/ss rf5/an10/c1in+/cv ref rf4/an9/c2in- rf3/an8/c2in+ rf2/an7/c1out rf0/an5 rf1/an6/c2out portf portj rj6/lb rj7/ub rj5/ce rj4/ba0 rj3/wrh rj2/wrl rj0/ale rj1/oe rg5/mclr /v pp mclr osc2/clko/ra6 rd0/psp0/ad0 ad7:ad0 a16, ad15:ad8 system bus interface note 1: the ccp2 pin placement depends on the ccp2mx and processor mode settings. 2: p1b and p1c pin placement depends on the eccpmx setting. porth rh3/a19:rh0/a16 rh7/an15/p1b (2) rh6/an14/p1c (2) rh5/an13 rh4/an12
pic18f6585/8585/6680/8680 ds30491c-page 12 ? 2004 microchip technology inc. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp rg5/mclr /v pp rg5 mclr v pp 716 9 i i p st st master clear (input) or programming voltage (input). general purpose input pin. master clear (reset) input. this pin is an active-low reset to the device. programming voltage input. osc1/clki osc1 clki 39 50 49 i i cmos/st cmos oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode; otherwise cmos. external clock source input. always associated with pin function osc1 (see osc1/clki, osc2/clko pins). osc2/clko/ra6 osc2 clko ra6 40 51 50 o o i/o ? ? ttl oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, osc2 pin outputs clko which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. general purpose i/o pin. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
? 2004 microchip technology inc. ds30491c-page 13 pic18f6585/8585/6680/8680 porta is a bidirectional i/o port. ra0/an0 ra0 an0 24 34 30 i/o i ttl analog digital i/o. analog input 0. ra1/an1 ra1 an1 23 33 29 i/o i ttl analog digital i/o. analog input 1. ra2/an2/v ref - ra2 an2 v ref - 22 32 28 i/o i i ttl analog analog digital i/o. analog input 2. a/d reference voltage (low) input. ra3/an3/v ref + ra3 an3 v ref + 21 31 27 i/o i i ttl analog analog digital i/o. analog input 3. a/d reference voltage (high) input. ra4/t0cki ra4 t0cki 28 39 34 i/o i st/od st digital i/o ? open-drain when configured as output. timer0 external clock input. ra5/an4/lvdin ra5 an4 lvdin 27 38 33 i/o i i ttl analog analog digital i/o. analog input 4. low-voltage detect input. ra6 see the osc2/clko/ra6 pin. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
pic18f6585/8585/6680/8680 ds30491c-page 14 ? 2004 microchip technology inc. portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-ups on all inputs. rb0/int0 rb0 int0 48 60 58 i/o i ttl st digital i/o. external interrupt 0. rb1/int1 rb1 int1 47 59 57 i/o i ttl st digital i/o. external interrupt 1. rb2/int2 rb2 int2 46 58 56 i/o i ttl st digital i/o. external interrupt 2. rb3/int3/ccp2 rb3 int3 ccp2 (1) 45 57 55 i/o i/o i/o ttl st st digital i/o. external interrupt 3. capture 2 input/compare 2 output/ pwm 2 output. rb4/kbi0 rb4 kbi0 44 56 54 i/o i ttl st digital i/o. interrupt-on-change pin. rb5/kbi1/pgm rb5 kbi1 pgm 43 55 53 i/o i i/o ttl st st digital i/o. interrupt-on-change pin. low-voltage icsp programming enable pin. rb6/kbi2/pgc rb6 kbi2 pgc 42 54 52 i/o i i/o ttl st st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming clock. rb7/kbi3/pgd rb7 kbi3 pgd 37 48 47 i/o i/o ttl st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming data. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
? 2004 microchip technology inc. ds30491c-page 15 pic18f6585/8585/6680/8680 portc is a bidirectional i/o port. rc0/t1oso/t13cki rc0 t1oso t13cki 30 41 36 i/o o i st ? st digital i/o. timer1 oscillator output. timer1/timer3 external clock input. rc1/t1osi/ccp2 rc1 t1osi ccp2 (1, 4) 29 40 35 i/o i i/o st cmos st digital i/o. timer1 oscillator input. ccp2 capture input/compare output/ pwm 2 output. rc2/ccp1/p1a rc2 ccp1 p1a 33 44 43 i/o i/o i/o st st st digital i/o. ccp1 capture input/compare output. ccp1 pwm output a. rc3/sck/scl rc3 sck scl 34 45 44 i/o i/o i/o st st st digital i/o. synchronous serial clock input/output for spi mode. synchronous serial clock input/output for i 2 c mode. rc4/sdi/sda rc4 sdi sda 35 46 45 i/o i i/o st st st digital i/o. spi data in. i 2 c data i/o. rc5/sdo rc5 sdo 36 47 46 i/o o st ? digital i/o. spi data out. rc6/tx/ck rc6 tx ck 31 42 37 i/o o i/o st ? st digital i/o. usart asynchronous transmit. usart synchronous clock (see rx/dt). rc7/rx/dt rc7 rx dt 32 43 38 i/o i i/o st st st digital i/o. usart 1 asynchronous receive. usart 1 synchronous data (see tx/ck). table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
pic18f6585/8585/6680/8680 ds30491c-page 16 ? 2004 microchip technology inc. portd is a bidirectional i/o port. these pins have ttl input buffers when external memory is enabled. rd0/psp0/ad0 rd0 psp0 (6) ad0 (3) 58 3 72 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 0. rd1/psp1/ad1 rd1 psp1 (6) ad1 (3) 55 67 69 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 1. rd2/psp2/ad2 rd2 psp2 (6) ad2 (3) 54 66 68 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 2. rd3/psp3/ad3 rd3 psp3 (6) ad3 (3) 53 65 67 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 3. rd4/psp4/ad4 rd4 psp4 (6) ad4 (3) 52 64 66 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 4. rd5/psp5/ad5 rd5 psp5 (6) ad5 (3) 51 63 65 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 5. rd6/psp6/ad6 rd6 psp6 (6) ad6 (3) 50 62 64 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 6. rd7/psp7/ad7 rd7 psp7 (6) ad7 (3) 49 61 63 i/o i/o i/o st ttl ttl digital i/o. parallel slave port data. external memory address/data 7. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
? 2004 microchip technology inc. ds30491c-page 17 pic18f6585/8585/6680/8680 porte is a bidirectional i/o port. re0/rd /ad8 re0 rd (6) ad8 (3) 211 4 i/o i i/o st ttl ttl digital i/o. read control for parallel slave port (see wr and cs pins). external memory address/data 8. re1/wr /ad9 re1 wr (6) ad9 (3) 110 3 i/o i i/o st ttl ttl digital i/o. write control for parallel slave port (see cs and rd pins). external memory address/data 9. re2/cs /ad10 re2 cs (6) ad10 (3) 64 9 78 i/o i i/o st ttl ttl digital i/o. chip select control for parallel slave port (see rd and wr ). external memory address/data 10. re3/ad11 re3 ad11 (3) 63 8 77 i/o i/o st ttl digital i/o. external memory address/data 11. re4/ad12 re4 ad12 (3) 62 7 76 i/o i/o st ttl digital i/o. external memory address/data 12. re5/ad13/p1c re5 ad13 (3) p1c (7) 61 6 75 i/o i/o i/o st ttl st digital i/o. external memory address/data 13. eccp1 pwm output c. re6/ad14/p1b re6 ad14 (3) p1b (7) 60 5 74 i/o i/o i/o st ttl st digital i/o. external memory address/data 14. eccp1 pwm output b. re7/ccp2/ad15 re7 ccp2 (1,4) ad15 (3) 59 4 73 i/o i/o i/o st st ttl digital i/o. capture 2 input/compare 2 output/ pwm 2 output. external memory address/data 15. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
pic18f6585/8585/6680/8680 ds30491c-page 18 ? 2004 microchip technology inc. portf is a bidirectional i/o port. rf0/an5 rf0 an5 18 28 24 i/o i st analog digital i/o. analog input 5. rf1/an6/c2out rf1 an6 c2out 17 27 23 i/o i o st analog st digital i/o. analog input 6. comparator 2 output. rf2/an7/c1out rf2 an7 c1out 16 26 18 i/o i o st analog st digital i/o. analog input 7. comparator 1 output. rf3/an8/c2in+ rf1 an8 c2in+ 15 25 17 i/o i i st analog analog digital i/o. analog input 8. comparator 2 input (+). rf4/an9/c2in- rf1 an9 c2in- 14 24 16 i/o i i st analog analog digital i/o. analog input 9. comparator 2 input (-). rf5/an10/c1in+/cv ref rf1 an10 c1in+ cv ref 13 23 15 i/o i i o st analog analog analog digital i/o. analog input 10. comparator 1 input (+). comparator v ref output. rf6/an11/c1in- rf6 an11 c1in- 12 22 14 i/o i i st analog analog digital i/o. analog input 11. comparator 1 input (-) rf7/ss rf7 ss 11 21 13 i/o i st ttl digital i/o. spi slave select input. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
? 2004 microchip technology inc. ds30491c-page 19 pic18f6585/8585/6680/8680 portg is a bidirectional i/o port. rg0/cantx1 rg0 cantx1 312 5 i/o o st ttl digital i/o. can bus transmit 1. rg1/cantx2 rg1 cantx2 413 6 i/o o st ttl digital i/o. can bus transmit 2. rg2/canrx rg2 canrx 514 7 i/o i st ttl digital i/o. can bus receive. rg3 rg3 615 8 i/o st digital i/o. rg4/p1d rg4 p1d 817 10 i/o o st ttl digital i/o. eccp1 pwm output d. rg5 7 16 9 i st general purpose input pin. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
pic18f6585/8585/6680/8680 ds30491c-page 20 ? 2004 microchip technology inc. porth is a bidirectional i/o port (5) . rh0/a16 rh0 a16 ?? 79 i/o o st ttl digital i/o. external memory address 16. rh1/a17 rh1 a17 ?? 80 i/o o st ttl digital i/o. external memory address 17. rh2/a18 rh2 a18 ?? 1 i/o o st ttl digital i/o. external memory address 18. rh3/a19 rh3 a19 ?? 2 i/o o st ttl digital i/o. external memory address 19. rh4/an12 rh4 an12 ?? 22 i/o i st analog digital i/o. analog input 12. rh5/an13 rh5 an13 ?? 21 i/o i st analog digital i/o. analog input 13. rh6/an14/p1c rh6 an14 p1c (7) ?? 20 i/o i i/o st analog st digital i/o. analog input 14. alternate ccp1 pwm output c. rh7/an15/p1b rh7 an15 p1b (7) ?? 19 i/o i st analog digital i/o. analog input 15. alternate ccp1 pwm output b. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
? 2004 microchip technology inc. ds30491c-page 21 pic18f6585/8585/6680/8680 portj is a bidirectional i/o port (5) . rj0/ale rj0 ale ?? 62 i/o o st ttl digital i/o. external memory address latch enable. rj1/oe rj1 oe ?? 61 i/o o st ttl digital i/o. external memory output enable. rj2/wrl rj2 wrl ?? 60 i/o o st ttl digital i/o. external memory write low control. rj3/wrh rj3 wrh ?? 59 i/o o st ttl digital i/o. external memory write high control. rj4/ba0 rj4 ba0 ?? 39 i/o o st ttl digital i/o. system bus byte address 0 control. rj5/ce ce ? ? 40 i/o o st ttl digital i/o external memory chip enable. rj6/lb rj6 lb ?? 42 i/o o st ttl digital i/o. external memory low byte select. rj7/ub rj7 ub ?? 41 i/o o st ttl digital i/o. external memory high byte select. v ss 9, 25, 41, 56 19, 36, 53, 68 11, 31, 51, 70 p ? ground reference for logic and i/o pins. v dd 10, 26, 38, 57 2, 20, 37, 49 12, 32, 48, 71 p ? positive supply for logic and i/o pins. av ss 20 30 26 p ? ground reference for analog modules. av dd 19 29 25 p ? positive supply for analog modules. nc ? 1, 18, 35, 52 ? ? ? no connect. table 1-2: pic18f6585/8585/6680/8680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pic18f6x8x pic18f8x8x tqfp plcc tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p = power od = open-drain (no p diode to v dd ) note 1: alternate assignment for ccp2 in all operating modes except microcontroller ? applies to pic18f8x8x only. 2: default assignment when ccp2mx is set. 3: external memory interface functions are only available on pic18f8x8x devices. 4: ccp2 is multiplexed with this pin by default when configured in microcontroller mode; otherwise, it is multiplexed with either rb3 or rc1. 5: porth and portj are only available on pic18f8x8x (80-pin) devices. 6: psp is available in microcontroller mode only. 7: on pic18f8x8x devices, these pins can be multiplexed with rh7/rh6 by changing the eccpmx configuration bit.
pic18f6585/8585/6680/8680 ds30491c-page 22 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 23 pic18f6585/8585/6680/8680 2.0 oscillator configurations 2.1 oscillator types the pic18f6585/8585/6680/8680 devices can be operated in eleven different oscillator modes. the user can program four configuration bits (fosc3, fosc2, fosc1 and fosc0) to select one of these eleven modes: 1. lp low-power crystal 2. xt crystal/resonator 3. hs high-speed crystal/resonator 4. rc external resistor/capacitor 5. ec external clock 6. ecio external clock with i/o pin enabled 7. hs+pll high-speed crystal/resonator with pll enabled 8. rcio external resistor/capacitor with i/o pin enabled 9. ecio+spll external clock with software controlled pll 10. ecio+pll external clock with pll and i/o pin enabled 11. hs+spll high-speed crystal/resonator with software control 2.2 crystal oscillator/ceramic resonators in xt, lp, hs, hs+pll or hs+spll oscillator modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation. figure 2-1 shows the pin connections. the pic18f6585/8585/6680/8680 oscillator design requires the use of a parallel cut crystal. figure 2-1: crystal/ceramic resonator operation (hs, xt or lp configuration) table 2-1: capacitor selection for ceramic resonators note: use of a series cut crystal may give a fre- quency out of the crystal manufacturers specifications. ranges tested: mode freq c1 c2 xt 455 khz 2.0 mhz 4.0 mhz 68-100 pf 15-68 pf 15-68 pf 68-100 pf 15-68 pf 15-68 pf hs 8.0 mhz 16.0 mhz 10-68 pf 10-22 pf 10-68 pf 10-22 pf these values are for design guidance only. see notes following this table. resonators used: 2.0 mhz murata erie csa2.00mg 0.5% 4.0 mhz murata erie csa4.00mg 0.5% 8.0 mhz murata erie csa8.00mt 0.5% 16.0 mhz murata erie csa16.00mx 0.5% all resonators used did not have built-in capacitors. note 1: higher capacitance increases the stability of the oscillator, but also increases the start-up time. 2: when operating below 3v v dd , or when using certain ceramic resonators at any voltage, it may be necessary to use high gain hs mode, try a lower frequency resonator, or switch to a crystal oscillator. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appro- priate values of external components, or verify oscillator performance. note 1: see table 2-1 and table 2-2 for recommended values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the oscillator mode chosen. c1 (1) c2 (1) xtal osc2 osc1 r f (3) sleep to logic pic18fxx80/xx85 r s (2) internal
pic18f6585/8585/6680/8680 ds30491c-page 24 ? 2004 microchip technology inc. table 2-2: capacitor selection for crystal oscillator an external clock source may also be connected to the osc1 pin in the hs, xt and lp modes, as shown in figure 2-2. figure 2-2: external clock input operation (hs, xt or lp osc configuration) 2.3 rc oscillator for timing insensitive applications, the ?rc? and ?rcio? device options offer additional cost savings. the rc oscillator frequency is a function of the supply voltage, the resistor (r ext ) and capacitor (c ext ) val- ues and the operating temperature. in addition to this, the oscillator frequency will vary from unit to unit, due to normal process parameter variation. furthermore, the difference in lead frame capacitance between pack- age types will also affect the oscillation frequency, especially for low c ext values. the user also needs to take into account variation due to tolerance of external r and c components used. figure 2-3 shows how the r/c combination is connected. in the rc oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-3: rc oscillator mode the rcio oscillator mode functions like the rc mode except that the osc2 pin becomes an additional gen- eral purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). ranges tested: mode freq c1 c2 lp 32.0 khz 33 pf 33 pf 200 khz 15 pf 15 pf xt 200 khz 47-68 pf 47-68 pf 1.0 mhz 15 pf 15 pf 4.0 mhz 15 pf 15 pf hs 4.0 mhz 15 pf 15 pf 8.0 mhz 15-33 pf 15-33 pf 20.0 mhz 15-33 pf 15-33 pf 25.0 mhz tbd tbd these values are for design guidance only. see notes following this table. crystals used 32.0 khz epson c-001r32.768k-a 20 ppm 200 khz std xtl 200.000khz 20 ppm 1.0 mhz ecs ecs-10-13-1 50 ppm 4.0 mhz ecs ecs-40-20-1 50 ppm 8.0 mhz epson ca-301 8.000m-c 30 ppm 20.0 mhz epson ca-301 20.000m-c 30 ppm note 1: higher capacitance increases the stability of the oscillator, but also increases the start-up time. 2: rs (see figure 2-1) may be required in hs mode, as well as xt mode, to avoid overdriving crystals with low drive level specifications. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appro- priate values of external components, or verify oscillator performance. osc1 osc2 open clock from ext. system pic18fxx80/xx85 osc2/clko c ext r ext pic18fxx80/xx85 osc1 f osc /4 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20pf
? 2004 microchip technology inc. ds30491c-page 25 pic18f6585/8585/6680/8680 2.4 external clock input the ec, ecio, ec+pll and ec+spll oscillator modes require an external clock source to be con- nected to the osc1 pin. the feedback device between osc1 and osc2 is turned off in these modes to save current. there is a maximum 1.5 s start-up required after a power-on reset, or wake-up from sleep mode. in the ec oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-4 shows the pin connections for the ec oscillator mode. figure 2-4: external clock input operation (ec configuration) the ecio oscillator mode functions like the ec mode, except that the osc2 pin becomes an additional gen- eral purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 2-5 shows the pin connections for the ecio oscillator mode. figure 2-5: external clock input operation (ecio configuration) 2.5 phase locked loop (pll) a phase locked loop circuit is provided as a programmable option for users that want to multiply the frequency of the incoming oscillator signal by 4. for an input clock frequency of 10 mhz, the internal clock frequency will be multiplied to 40 mhz. this is useful for customers who are concerned with emi due to high-frequency crystals. the pll can only be enabled when the oscillator config- uration bits are programmed for high-speed oscillator or external clock mode. if they are programmed for any other mode, the pll is not enabled and the system clock will come directly from osc1. there are two types of pll modes: software controlled pll and configuration bits controlled pll. in software controlled pll mode, pic18f6585/8585/6680/8680 executes at regular clock frequency after all reset conditions. during execution, application can enable pll and switch to 4x clock frequency operation by setting the pllen bit in the osccon register. in configuration bits controlled pll mode, pic18f6585/8585/6680/8680 always executes with 4x clock frequency. the type of pll is selected by programming the fosc<3:0> configuration bits in the config1h configuration register. the oscillator mode is specified during device programming. a pll lock timer is used to ensure that the pll has locked before device execution starts. the pll lock timer has a time-out that is called t pll . figure 2-6: pll block diagram osc1 osc2 f osc /4 clock from ext. system pic18fxx80/xx85 osc1 i/o (osc2) ra6 clock from ext. system pic18fxx80/xx85 mux vco loop filter divide by 4 pll enable f in f out sysclk phase comparator
pic18f6585/8585/6680/8680 ds30491c-page 26 ? 2004 microchip technology inc. 2.6 oscillator switching feature the pic18f6585/8585/6680/8680 devices include a feature that allows the system clock source to be switched from the main oscillator to an alternate low-frequency clock source. for the pic18f6585/8585/6680/8680 devices, this alternate clock source is the timer1 oscillator. if a low-frequency crystal (32 khz, for example) has been attached to the timer1 oscillator pins and the timer1 oscillator has been enabled, the device can switch to a low-power execution mode. figure 2-7 shows a block diagram of the system clock sources. the clock switching feature is enabled by programming the oscillator switching enable (oscsen ) bit in configuration register, config1h, to a ? 0 ?. clock switching is disabled in an erased device. see section 12.0 ?timer1 module? for further details of the timer1 oscillator. see section 24.0 ?special features of the cpu? for configuration register details. figure 2-7: device clock sources pic18fxx80/xx85 t osc 4 x pll t t 1 p t sclk clock source mux tosc/4 timer1 oscillator t1oscen enable oscillator t1oso t1osi clock source option for other modules osc1 osc2 sleep main oscillator
? 2004 microchip technology inc. ds30491c-page 27 pic18f6585/8585/6680/8680 2.6.1 system clock switch bit the system clock source switching is performed under software control. the system clock switch bits, scs1:scs0 (osccon<1:0>), control the clock switch- ing. when the scs0 bit is ? 0 ?, the system clock source comes from the main oscillator that is selected by the fosc configuration bits in configuration register, config1h. when the scs0 bit is set, the system clock source will come from the timer1 oscillator. the scs0 bit is cleared on all forms of reset. when fosc bits are programmed for software pll mode, the scs1 bit can be used to select between pri- mary oscillator/clock and pll output. the scs1 bit will only have an effect on the system clock if the pll is enabled (pllen = 1 ) and locked (lock = 1 ), else it will be forced clear. when programmed with configuration controlled pll mode, the scs1 bit will be forced clear. register 2-1: osccon register note: the timer1 oscillator must be enabled and operating to switch the system clock source. the timer1 oscillator is enabled by setting the t1oscen bit in the timer1 control register (t1con). if the timer1 oscillator is not enabled, then any write to the scs0 bit will be ignored (scs0 bit forced cleared) and the main oscillator will continue to be the system clock source. u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ? lock pllen scs1 scs0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 lock: phase lock loop lock status bit 1 = phase lock loop output is stable as system clock 0 = phase lock loop output is not stable and output cannot be used as system clock bit 2 pllen (1) : phase lock loop enable bit 1 = enable phase lock loop output as system clock 0 = disable phase lock loop bit 1 scs1: system clock switch bit 1 when pllen and lock bits are set: 1 = use pll output 0 = use primary oscillator/clock input pin when pllen or lock bit is cleared: bit is forced clear. bit 0 scs0 (2) : system clock switch bit 0 when oscsen configuration bit = 0 and t1oscen bit = 1 : 1 = switch to timer1 oscillator/clock pin 0 = use primary oscillator/clock input pin when oscsen and t1oscen are in other states: bit is forced clear. note 1: pllen bit is ignored when configured for ecio+pll and hs+pll. this bit is used in ecio+spll and hs+spll modes only. 2: the setting of scs0 = 1 supersedes scs1 = 1 . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 28 ? 2004 microchip technology inc. 2.6.2 oscillator transitions pic18f6585/8585/6680/8680 devices contain circuitry to prevent ?glitches? when switching between oscillator sources. essentially, the circuitry waits for eight rising edges of the clock source that the processor is switch- ing to. this ensures that the new clock source is stable and that its pulse width will not be less than the shortest pulse width of the two clock sources. a timing diagram, indicating the transition from the main oscillator to the timer1 oscillator, is shown in figure 2-8. the timer1 oscillator is assumed to be run- ning all the time. after the scs0 bit is set, the processor is frozen at the next occurring q1 cycle. after eight synchronization cycles are counted from the timer1 oscillator, operation resumes. no additional delays are required after the synchronization cycles. the sequence of events that takes place when switch- ing from the timer1 oscillator to the main oscillator will depend on the mode of the main oscillator. in addition to eight clock cycles of the main oscillator, additional delays may take place. if the main oscillator is configured for an external crystal (hs, xt, lp), then the transition will take place after an oscillator start-up time (t ost ) has occurred. a timing diagram, indicating the transition from the timer1 oscillator to the main oscillator for hs, xt and lp modes, is shown in figure 2-9. figure 2-8: timing diagram for transiti on from osc1 to timer1 oscillator figure 2-9: timing for transition between timer1 and osc1 (hs, xt, lp) q3 q2 q1 q4 q3 q2 osc1 internal scs (osccon<0>) program pc + 2 pc note: t dly is the delay from scs high to first count of transition circuit. q1 t1osi q4 q1 pc + 4 q1 t scs clock counter system q2 q3 q4 q1 t dly t t 1 p t osc 2 1 34 5678 q3 q3 q4 q1 q2 q3 q4 q1 q2 osc1 internal scs (osccon<0>) program pc pc + 2 note: t ost = 1024 t osc (drawing not to scale). t1osi system clock t ost q1 pc + 6 t t 1 p t osc t scs 12345678 counter
? 2004 microchip technology inc. ds30491c-page 29 pic18f6585/8585/6680/8680 if the main oscillator is configured for hs mode with pll active, an oscillator start-up time (t ost ) plus an additional pll time-out (t pll ) will occur. the pll time- out is typically 2 ms and allows the pll to lock to the main oscillator frequency. a timing diagram, indicating the transition from the timer1 oscillator to the main oscillator for hs-pll mode, is shown in figure 2-10. if the main oscillator is configured for ec mode with pll active, only the pll time-out (t pll ) will occur. the pll time-out is typically 2 ms and allows the pll to lock to the main oscillator frequency. a timing diagram, indicat- ing the transition from the timer1 oscillator to the main oscillator for ec with pll ac tive, is shown in figure 2-11. figure 2-10: timing for transition between timer1 and osc1 (hs with pll active, scs1 = 1 ) figure 2-11: timing for transition between timer1 and osc1 (ec with pll active, scs1 = 1 ) q4 q1 q1 q2 q3 q4 q1 q2 osc1 internal system scs (osccon<0>) program counter pc pc + 2 note: t ost = 1024 t osc (drawing not to scale). t1osi clock t ost q3 pc + 4 t pll t osc t t 1 p t scs q4 pll clock input 1 23 4 56 78 q4 q1 q1 q2 q3 q4 q1 q2 osc1 internal system scs (osccon<0>) program counter pc pc + 2 t1osi clock q3 pc + 4 t pll t osc t t 1 p t scs q4 pll clock input 1 23 4 56 78
pic18f6585/8585/6680/8680 ds30491c-page 30 ? 2004 microchip technology inc. if the main oscillator is configured in the rc, rcio, ec or ecio modes, there is no oscillator start-up time-out. operation will resume after eight cycles of the main oscillator have been counted. a timing diagram, indi- cating the transition from the timer1 oscillator to the main oscillator for rc, rcio, ec and ecio modes, is shown in figure 2-12. figure 2-12: timing for transition between timer1 and osc1 (rc, ec) q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 osc1 internal system scs (osccon<0>) program pc pc + 2 note: rc oscillator mode assumed. pc + 4 t1osi clock q4 t t 1 p t osc t scs 1 23 45 6 78 counter
? 2004 microchip technology inc. ds30491c-page 31 pic18f6585/8585/6680/8680 2.7 effects of sleep mode on the on-chip oscillator when the device executes a sleep instruction, the on- chip clocks and oscillator are turned off and the device is held at the beginning of an instruction cycle (q1 state). with the oscillator off, the osc1 and osc2 signals will stop oscillating. since all the transistor switching currents have been removed, sleep mode achieves the lowest current consumption of the device (only leakage currents). enabling any on-chip feature that will operate during sleep will increase the current consumed during sleep. the user can wake from sleep through external reset, watchdog timer reset, or through an interrupt. table 2-3: osc1 and osc2 pin states in sleep mode 2.8 power-up delays power-up delays are controlled by two timers so that no external reset circuitry is required for most applica- tions. the delays ensure that the device is kept in reset until the device power supply and clock are sta- ble. for additional information on reset operation, see section 3.0 ?reset? . the first timer is the power-up timer (pwrt) which optionally provides a fixed delay of 72 ms (nominal) on power-up only (por and bor). the second timer is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. with the pll enabled (hs+pll and ec+pll oscillator mode), the time-out sequence following a power-on reset is different from other oscillator modes. the time-out sequence is as follows: first, the pwrt time- out is invoked after a por time delay has expired. then, the oscillator start-up timer (ost) is invoked. however, this is still not a sufficient amount of time to allow the pll to lock at high frequencies. the pwrt timer is used to provide an additional fixed 2 ms (nominal) time-out to allow the pll ample time to lock to the incoming clock frequency. osc mode osc1 pin osc2 pin rc floating, external resistor should pull high at logic low rcio floating, external resistor should pull high configured as porta, bit 6 ecio floating configured as porta, bit 6 ec floating at logic low lp, xt, and hs feedback inverter disabled at quiescent voltage level feedback inverter disabled at quiescent voltage level note: see table 3-1 in section 3.0 ?reset? , for time-outs due to sleep and mclr reset.
pic18f6585/8585/6680/8680 ds30491c-page 32 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 33 pic18f6585/8585/6680/8680 3.0 reset the pic18f6585/8585/6680/8680 devices differentiate between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during sleep d) watchdog timer (wdt) reset (during normal operation) e) programmable brown-out reset (bor) f) reset instruction g) stack full reset h) stack underflow reset most registers are unaffected by a reset. their status is unknown on por and unchanged by all other resets. the other registers are forced to a ?reset state? on power-on reset, mclr , wdt reset, brown- out reset, mclr reset during sleep and by the reset instruction. most registers are not affected by a wdt wake-up since this is viewed as the resumption of normal oper- ation. status bits from the rcon register, ri , to , pd , por and bor, are set or cleared differently in different reset situations, as indicated in table 3-2. these bits are used in software to determine the nature of the reset. see table 3-3 for a full description of the reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 3-1. the enhanced mcu devices have a mclr noise filter in the mclr reset path. the filter will detect and ignore small pulses. the mclr pin is not driven low by any internal resets, including the wdt. figure 3-1: simplified block diagram of on-chip reset circuit s r q external reset mclr v dd osc1 wdt module v dd rise detect ost/pwrt on-chip rc osc (1) wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 10-bit ripple counter reset enable ost (2) enable pwrt sleep note 1: this is a separate oscillator from the rc oscillator of the clki pin. 2: see table 3-1 for time-out situations. brown-out reset boren reset instruction stack pointer stack full/underflow reset
pic18f6585/8585/6680/8680 ds30491c-page 34 ? 2004 microchip technology inc. 3.1 power-on reset (por) a power-on reset pulse is generated on-chip when v dd rise is detected. to take advantage of the por cir- cuitry, tie the mclr pin through a 1 k ? to 10 k ? resis- tor to v dd . this will eliminate external rc components usually needed to create a power-on reset delay. a minimum rise rate for v dd is specified (parameter d004). for a slow rise time, see figure 3-2. when the device starts normal operation (i.e., exits the reset condition), device operating parameters (volt- age, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. figure 3-2: external power-on reset circuit (for slow v dd power-up) 3.2 power-up timer (pwrt) the power-up timer provides a fixed nominal time-out (parameter #33) only on power-up from the por. the power-up timer operates on an internal rc oscillator. the chip is kept in reset as long as the pwrt is active. the pwrt?s time delay allows v dd to rise to an acceptable level. a configuration bit is provided to enable/disable the pwrt. the power-up time delay will vary from chip-to-chip due to v dd , temperature and process variation. see dc parameter #33 for details. 3.3 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides 1024 oscillator cycles (from osc1 input) delay after the pwrt delay is over (parameter #32). this ensures that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp and hs modes and only on power-on reset, or wake-up from sleep. 3.4 pll lock time-out with the pll enabled, the time-out sequence following a power-on reset is different from other oscillator modes. a portion of the power-up timer is used to pro- vide a fixed time-out that is sufficient for the pll to lock to the main oscillator frequency. this pll lock time-out (t pll ) is typically 2 ms and follows the oscillator start-up time-out (ost). 3.5 brown-out reset (bor) a configuration bit, boren, can disable (if clear/ programmed), or enable (if set) the brown-out reset circuitry. if v dd falls below parameter d005 for greater than parameter #35, the brown-out situation will reset the chip. a reset may not occur if v dd falls below parameter d005 for less than parameter #35. the chip will remain in brown-out reset until v dd rises above bv dd . if the power-up timer is enabled, it will be invoked after v dd rises above bv dd ; it then will keep the chip in reset for an additional time delay (parame- ter #33). if v dd drops below bv dd while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be initialized. once v dd rises above bv dd , the power-up timer will execute the additional time delay. 3.6 time-out sequence on power-up, the time-out sequence is as follows: first, pwrt time-out is invoked after the por time delay has expired. then, ost is activated. the total time-out will vary based on oscillator configuration and the status of the pwrt. for example, in rc mode with the pwrt disabled, there will be no time-out at all. figure 3-3, figure 3-4, figure 3-5, figure 3-6 and figure 3-7 depict time-out sequences on power-up. since the time-outs occur from the por pulse, the time-outs will expire if mclr is kept low long enough. bringing mclr high will begin execution immediately (figure 3-5). this is useful for testing purposes or to synchronize more than one pic18fxx8x device operating in parallel. table 3-2 shows the reset conditions for some special function registers while table 3-3 shows the reset conditions for all of the registers. note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow . the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure tha t the voltage drop across r does not violate the device?s electrical specification. 3: r1 = 1 k ? to 10 k ? will limit any current flow- ing into mclr from external capacitor c, in the event of mclr/ v pp pin breakdown due to electrostatic discharge (esd) or electrica l overstress (eos). c r1 r d v dd mclr pic18fxx8x
? 2004 microchip technology inc. ds30491c-page 35 pic18f6585/8585/6680/8680 table 3-1: time-out in various situations register 3-1: rcon register bits and positions table 3-2: status bits, their significanc e and the initialization condition for rcon register oscillator configuration power-up (2) brown-out wake-up from sleep or oscillator switch pwrte = 0 pwrte = 1 hs with pll enabled (1) 72 ms + 1024 t osc + 2ms 1024 t osc + 2 ms 1024 t osc + 2 ms 1024 t osc + 2 ms ec with pll enabled (1) 72 ms + 2ms 1.5 s + 2 ms 2 ms 1.5 s + 2 ms hs, xt, lp 72 ms + 1024 t osc 1024 t osc 1024 t osc 1024 t osc ec 72 ms 1.5 s1.5 s1.5 s (3) external rc 72 ms 1.5 s1.5 s1.5 s note 1: 2 ms is the nominal time required for the 4x pll to lock. 2: 72 ms is the nominal power-up timer delay if implemented. 3: 1.5 s is the recovery time from sleep. there is no recovery time from oscillator switch. r/w-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-0 ipen ? ?ri to pd por bor bit 7 bit 0 note: refer to section 4.14 ?rcon register? for bit definitions. condition program counter rcon register ri to pd por bor stkful stkunf power-on reset 0000h 0--1 1100 1 1 1 0 0 u u mclr reset during normal operation 0000h 0--u uuuu u u u u u u u software reset during normal operation 0000h 0--0 uuuu 0 u u u u u u stack full reset during normal operation 0000h 0--u uu11 u u u u u u 1 stack underflow reset during normal operation 0000h 0--u uu11 u u u u u 1 u mclr reset during sleep 0000h 0--u 10uu u 1 0 u u u u wdt reset 0000h 0--u 01uu 1 0 1 u u u u wdt wake-up pc + 2 u--u 00uu u 0 0 u u u u brown-out reset 0000h 0--1 11u0 1 1 1 1 0 u u interrupt wake-up from sleep pc + 2 (1) u--u 00uu u 1 0 u u u u legend: u = unchanged, x = unknown, ? = unimplemented bit, read as ? 0 ? note 1: when the wake-up is due to an interrupt and the gieh or giel bits are set, the pc is loaded with the interrupt vector (000008h or 000018h).
pic18f6585/8585/6680/8680 ds30491c-page 36 ? 2004 microchip technology inc. table 3-3: initialization co nditions for all registers register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt tosu pic18f6x8x pic18f8x8x ---0 0000 ---0 0000 ---0 uuuu (3) tosh pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu (3) tosl pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu (3) stkptr pic18f6x8x pic18f8x8x 00-0 0000 uu-0 0000 uu-u uuuu (3) pclatu pic18f6x8x pic18f8x8x ---0 0000 ---0 0000 ---u uuuu pclath pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu pcl pic18f6x8x pic18f8x8x 0000 0000 0000 0000 pc + 2 (2) tblptru pic18f6x8x pic18f8x8x --00 0000 --00 0000 --uu uuuu tblptrh pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu tblptrl pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu tablat pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu prodh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu prodl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu intcon pic18f6x8x pic18f8x8x 0000 000x 0000 000x uuuu uuuu (1) intcon2 pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu (1) intcon3 pic18f6x8x pic18f8x8x 1100 0000 1100 0000 uuuu uuuu (1) indf0 pic18f6x8x pic18f8x8x n/a n/a n/a postinc0 pic18f6x8x pic18f8x8x n/a n/a n/a postdec0 pic18f6x8x pic18f8x8x n/a n/a n/a preinc0 pic18f6x8x pic18f8x8x n/a n/a n/a plusw0 pic18f6x8x pic18f8x8x n/a n/a n/a fsr0h pic18f6x8x pic18f8x8x ---- xxxx ---- uuuu ---- uuuu fsr0l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu wreg pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu indf1 pic18f6x8x pic18f8x8x n/a n/a n/a postinc1 pic18f6x8x pic18f8x8x n/a n/a n/a postdec1 pic18f6x8x pic18f8x8x n/a n/a n/a preinc1 pic18f6x8x pic18f8x8x n/a n/a n/a plusw1 pic18f6x8x pic18f8x8x n/a n/a n/a legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 37 pic18f6585/8585/6680/8680 fsr1h pic18f6x8x pic18f8x8x ---- xxxx ---- uuuu ---- uuuu fsr1l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu bsr pic18f6x8x pic18f8x8x ---- 0000 ---- 0000 ---- uuuu indf2 pic18f6x8x pic18f8x8x n/a n/a n/a postinc2 pic18f6x8x pic18f8x8x n/a n/a n/a postdec2 pic18f6x8x pic18f8x8x n/a n/a n/a preinc2 pic18f6x8x pic18f8x8x n/a n/a n/a plusw2 pic18f6x8x pic18f8x8x n/a n/a n/a fsr2h pic18f6x8x pic18f8x8x ---- xxxx ---- uuuu ---- uuuu fsr2l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu status pic18f6x8x pic18f8x8x ---x xxxx ---u uuuu ---u uuuu tmr0h pic18f6x8x pic18f8x8x 0000 0000 uuuu uuuu uuuu uuuu tmr0l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu t0con pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu osccon pic18f6x8x pic18f8x8x ---- 0000 ---- 0000 ---- uuuu lvdcon pic18f6x8x pic18f8x8x --00 0101 --00 0101 --uu uuuu wdtcon pic18f6x8x pic18f8x8x ---- ---0 ---- ---0 ---- ---u rcon (4) pic18f6x8x pic18f8x8x 0--q 11qq 0--q qquu u--u qquu tmr1h pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu tmr1l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu t1con pic18f6x8x pic18f8x8x 0-00 0000 u-uu uuuu u-uu uuuu tmr2 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu pr2 pic18f6x8x pic18f8x8x 1111 1111 1111 1111 1111 1111 t2con pic18f6x8x pic18f8x8x -000 0000 -000 0000 -uuu uuuu sspbuf pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu sspadd pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu sspstat pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu sspcon1 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu sspcon2 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 38 ? 2004 microchip technology inc. adresh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu adresl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu adcon0 pic18f6x8x pic18f8x8x --00 0000 --00 0000 --uu uuuu adcon1 pic18f6x8x pic18f8x8x --00 0000 --00 0000 --uu uuuu adcon2 pic18f6x8x pic18f8x8x 0-00 0000 0-00 0000 u-uu uuuu ccpr1h pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu ccpr1l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu ccp1con pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu ccpr2h pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu ccpr2l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu ccp2con pic18f6x8x pic18f8x8x --00 0000 --00 0000 --uu uuuu ccpas1 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu cvrcon pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu cmcon pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu tmr3h pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu tmr3l pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu t3con pic18f6x8x pic18f8x8x 0000 0000 uuuu uuuu uuuu uuuu pspcon pic18f6x8x pic18f8x8x 0000 ---- 0000 ---- uuuu ---- spbrg pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rcreg pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu txreg pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu txsta pic18f6x8x pic18f8x8x 0000 0010 0000 0010 uuuu uuuu rcsta pic18f6x8x pic18f8x8x 0000 000x 0000 000x uuuu uuuu eeadrh pic18f6x8x pic18f8x8x ---- --00 ---- --00 ---- --uu eeadr pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu eedata pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu eecon2 pic18f6x8x pic18f8x8x xx-0 x000 uu-0 u000 uu-0 u000 eecon1 pic18f6x8x pic18f8x8x 00-0 x000 00-0 u000 uu-u uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 39 pic18f6585/8585/6680/8680 ipr3 pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu pir3 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu pie3 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu ipr2 pic18f6x8x pic18f8x8x -1-1 1111 -1-1 1111 -u-u uuuu pir2 pic18f6x8x pic18f8x8x -0-0 0000 -0-0 0000 -u-u uuuu (1) pie2 pic18f6x8x pic18f8x8x -0-0 0000 -0-0 0000 -u-u uuuu ipr1 pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu pir1 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu (1) pie1 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu memcon pic18f6x8x pic18f8x8x 0-00 --00 0-00 --00 u-uu --uu trisj pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trish pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trisg pic18f6x8x pic18f8x8x ---1 1111 ---1 1111 ---u uuuu trisf pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trise pic18f6x8x pic18f8x8x 0000 -111 0000 -111 uuuu -uuu trisd pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trisc pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trisb pic18f6x8x pic18f8x8x 1111 1111 1111 1111 uuuu uuuu trisa (5,6) pic18f6x8x pic18f8x8x -111 1111 (5) -111 1111 (5) -uuu uuuu (5) latj pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu lath pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu latg pic18f6x8x pic18f8x8x ---x xxxx ---u uuuu ---u uuuu latf pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu late pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu latd pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu latc pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu latb pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu lata (5,6) pic18f6x8x pic18f8x8x -xxx xxxx (5) -uuu uuuu (5) -uuu uuuu (5) table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 40 ? 2004 microchip technology inc. portj pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu porth pic18f6x8x pic18f8x8x 0000 xxxx 0000 uuuu uuuu uuuu portg pic18f6x8x pic18f8x8x --xx xxxx --uu uuuu --uu uuuu portf pic18f6x8x pic18f8x8x x000 0000 u000 0000 u000 0000 porte pic18f6x8x pic18f8x8x ---- -000 ---- -000 ---- -uuu portd pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu portc pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu portb pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu porta (5,6) pic18f6x8x pic18f8x8x -x0x 0000 (5) -u0u 0000 (5) -uuu uuuu (5) spbrgh pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu baudcon pic18f6x8x pic18f8x8x -1-0 0-00 -1-0 0-00 -u-u u-uu eccp1del pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu ecancon pic18f6x8x pic18f8x8x 0001 0000 0001 0000 uuuu uuuu txerrcnt pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxerrcnt pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu comstat pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu ciocon pic18f6x8x pic18f8x8x 0000 ---- 0000 ---- uuuu ---- brgcon3 pic18f6x8x pic18f8x8x 00-- -000 00-- -000 uu-- -uuu brgcon2 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu brgcon1 pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu cancon pic18f6x8x pic18f8x8x 1000 000- 1000 000- uuuu uuu- canstat pic18f6x8x pic18f8x8x 100- 000- 100- 000- uuu- uuu- rxb0d7 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d6 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d5 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d4 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d3 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d2 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d1 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0d0 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0dlc pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 41 pic18f6585/8585/6680/8680 rxb0eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0sidl pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu rxb0sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb0con pic18f6x8x pic18f8x8x 000- 0000 000- 0000 uuu- uuuu rxb1d7 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d6 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d5 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d4 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d3 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d2 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d1 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1d0 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1dlc pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu rxb1eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1sidl pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu rxb1sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxb1con pic18f6x8x pic18f8x8x 000- 0000 000- 0000 uuu- uuuu txb0d7 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d6 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d5 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d4 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d3 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d2 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d1 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0d0 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0dlc pic18f6x8x pic18f8x8x -x-- xxxx -u-- uuuu -u-- uuuu txb0eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu txb0sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 42 ? 2004 microchip technology inc. txb0sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb0con pic18f6x8x pic18f8x8x 0000 0-00 0000 0-00 uuuu u-uu txb1d7 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d6 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d5 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d4 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d3 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d2 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d1 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1d0 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1dlc pic18f6x8x pic18f8x8x -x-- xxxx -u-- uuuu -u-- uuuu txb1eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb1sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- uu-u txb1sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu txb1con pic18f6x8x pic18f8x8x 0000 0-00 0000 0-00 uuuu u-uu txb2d7 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d6 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d5 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d4 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d3 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d2 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d1 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2d0 pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu 0uuu uuuu txb2dlc pic18f6x8x pic18f8x8x -x-- xxxx -u-- uuuu -u-- uuuu txb2eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb2eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu txb2sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu txb2sidh pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu txb2con pic18f6x8x pic18f8x8x 0000 0-00 0000 0-00 uuuu u-uu rxm1eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 43 pic18f6585/8585/6680/8680 rxm1eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxm1sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxm1sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxm0sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxm0sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf5sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf5sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf4sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf4sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf3sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf3sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf2sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf2sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf1eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf1eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf1sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf1sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidl pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf0sidl pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf0sidh pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 44 ? 2004 microchip technology inc. b5d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b5eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b5sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b5sidh (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b5con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu b4d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b4eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b4sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b4con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu b3d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 45 pic18f6585/8585/6680/8680 b3d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b3eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b3sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b3con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu b2d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b2eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b2sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b2con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu b1d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 46 ? 2004 microchip technology inc. b1d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b1eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b1sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b1con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu b0d7 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d6 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d5 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d4 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d3 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d2 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d1 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0d0 (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0dlc (7) pic18f6x8x pic18f8x8x -xxx xxxx -uuu uuuu -uuu uuuu b0eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0sidl (7) pic18f6x8x pic18f8x8x xxxx x-xx uuuu u-uu uuuu u-uu b0sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu b0con (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu txbie (7) pic18f6x8x pic18f8x8x ---0 00-- ---u uu-- ---u uu-- bie0 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu bsel0 (7) pic18f6x8x pic18f8x8x 0000 00-- 0000 00-- uuuu uu-- msel3 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu msel2 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu msel1 (7) pic18f6x8x pic18f8x8x 0000 0101 0000 0101 uuuu uuuu msel0 (7) pic18f6x8x pic18f8x8x 0101 0000 0101 0000 uuuu uuuu sdflc (7) pic18f6x8x pic18f8x8x ---0 0000 ---0 0000 -u-- uuuu rxfcon1 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 47 pic18f6585/8585/6680/8680 rxfcon0 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon7 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon6 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon5 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon4 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon3 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxfbcon2 (7) pic18f6x8x pic18f8x8x 0001 0001 0001 0001 uuuu uuuu rxfbcon1 (7) pic18f6x8x pic18f8x8x 0001 0001 0001 0001 uuuu uuuu rxfbcon0 (7) pic18f6x8x pic18f8x8x 0000 0000 0000 0000 uuuu uuuu rxf15eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf15eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf15sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf15sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf14sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf14sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf13eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf13eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf13sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf13sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf12sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf12sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf11sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu uuu- u-uu rxf11sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu uuuu uuuu rxf10eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf10eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu table 3-3: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 48 ? 2004 microchip technology inc. rxf10sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu -uuu uuuu rxf10sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf9eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf9eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf9sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu -uuu uuuu rxf9sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf8eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf8eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf8sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu -uuu uuuu rxf8sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf7eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf7eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf7sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu -uuu uuuu rxf7sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf6eidl (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf6eidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu rxf6sidl (7) pic18f6x8x pic18f8x8x xxx- x-xx uuu- u-uu -uuu uuuu rxf6sidh (7) pic18f6x8x pic18f8x8x xxxx xxxx uuuu uuuu -uuu uuuu table 3-3: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets wdt reset reset instruction stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 3-2 for reset value for specific condition. 5: bit 6 of porta, lata, and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disabled and read ? 0 ?. 6: bit 6 of porta, lata and trisa are not available on all devices. when unimplemented, they read ? 0 ?. 7: this register reads all ? 0 ?s until ecan is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 49 pic18f6585/8585/6680/8680 figure 3-3: time-out sequence on power-up (mclr tied to v dd via 1 k ? resistor) figure 3-4: time-out sequence on power-up (mclr not tied to v dd ): case 1 figure 3-5: time-out sequence on power-up (mclr not tied to v dd ): case 2 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost
pic18f6585/8585/6680/8680 ds30491c-page 50 ? 2004 microchip technology inc. figure 3-6: slow rise time (mclr tied to v dd via 1 k ? resistor) figure 3-7: time-out sequence on por w/ pll enabled (mclr tied to v dd via 1 k ? resistor) v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost t pwrt t ost v dd mclr iinternal por pwrt time-out ost time-out internal reset pll time-out t pll note: t ost = 1024 clock cycles. t pll 2 ms max. first three stages of the pwrt timer.
? 2004 microchip technology inc. ds30491c-page 51 pic18f6585/8585/6680/8680 4.0 memory organization there are three memory blocks in pic18f6585/8585/6680/8680 devices. they are:  program memory  data ram  data eeprom data and program memory use separate busses which allows for concurrent access of these blocks. additional detailed information for flash program memory and data eeprom is provided in section 5.0 ?flash program memory? and section 7.0 ?data eeprom memory? , respectively. in addition to on-chip flash, the pic18f8x8x devices are also capable of accessing external program mem- ory through an external memory bus. depending on the selected operating mode (discussed in section 4.1.1 ?pic18f8x8x program memory modes? ), the controllers may access either internal or external pro- gram memory exclusively, or both internal and external memory in selected blocks. additional information on the external memory interface is provided in section 6.0 ?external memory interface? . 4.1 program memory organization a 21-bit program counter is capable of addressing the 2-mbyte program memory space. accessing a location between the physically implemented memory and the 2-mbyte address will cause a read of all ? 0 ?s (a nop instruction). the pic18f6585 and pic18f8585 each have 48 kbytes of on-chip flash memory, while the pic18f6680 and pic18f8680 have 64 kbytes of flash. this means that pic18fx585 devices can store inter- nally up to 24,576 single-word instructions and pic18fx680 devices can store up to 32,768 single-word instructions. the reset vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h. figure 4-1 shows the program memory map for pic18f6585/8585 devices while figure 4-2 shows the program memory map for pic18f6680/8680 devices. 4.1.1 pic18f8x8x program memory modes pic18f8x8x devices differ significantly from their pic18 predecessors in their utilization of program memory. in addition to available on-chip flash program memory, these controllers can also address up to 2 mbytes of external program memory through the external memory interface. there are four distinct operating modes available to the controllers:  microprocessor (mp)  microprocessor with boot block (mpbb)  extended microcontroller (emc)  microcontroller (mc) the program memory mode is determined by setting the two least significant bits of the config3l config- uration byte, as shown in register 4-1. (see also section 24.1 ?configuration bits? for additional details on the device configuration bits.) the program memory modes operate as follows: the microprocessor mode permits access only to external program memory; the contents of the on-chip flash memory are ignored. the 21-bit program counter permits access to a 2-mbyte linear program memory space. the microprocessor with boot block mode accesses on-chip flash memory from addresses 000000h to 0007ffh. above this, external program memory is accessed all the way up to the 2-mbyte limit. program execution auto- matically switches between the two memories as required. the microcontroller mode accesses only on-chip flash memory. attempts to read above the physical limit of the on-chip flash (0bfffh for the pic18f8585, 0ffffh for the pic18f8680) causes a read of all ? 0 ?s (a nop instruction). the microcontroller mode is the only operating mode available to pic18f6x8x devices. the extended microcontroller mode allows access to both internal and external program memories as a single block. the device can access its entire on-chip flash memory; above this, the device accesses external program mem- ory up to the 2-mbyte program space limit. as with boot block mode, execution automatically switches between the two memories as required. in all modes, the microcontroller has complete access to data ram and eeprom. figure 4-3 compares the memory maps of the different program memory modes. the differences between on- chip and external memory access limitations are more fully explained in table 4-1.
pic18f6585/8585/6680/8680 ds30491c-page 52 ? 2004 microchip technology inc. figure 4-1: internal program memory map and stack for pic18f6585/8585 figure 4-2: internal program memory map and stack for pic18f6680/8680 table 4-1: memory access for pic18f8x8x program memory modes pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 000000h 000018h on-chip flash program memory high priority interrupt vector 000008h user memory space 1fffffh 00c000h 00bfffh read ? 0 ? 200000h pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 000000h 000018h 010000h 00ffffh on-chip flash program memory high priority interrupt vector 000008h user memory space read ? 0 ? 1fffffh 200000h operating mode internal program memory external program memory execution from table read from table write to execution from table read from table write to microprocessor no access no access no access yes yes yes microprocessor w/ boot block yes yes yes yes yes yes microcontroller yes yes yes no access no access no access extended microcontroller yes yes yes yes yes yes
? 2004 microchip technology inc. ds30491c-page 53 pic18f6585/8585/6680/8680 register 4-1: config3l configuration byte figure 4-3: memory maps for pic18f 8x8x program memory modes r/p-1 u-0 u-0 u-0 u-0 u-0 r/p-1 r/p-1 wait ? ? ? ? ?pm1pm0 bit 7 bit 0 bit 7 wait: external bus data wait enable bit 1 = wait selections unavailable, device will not wait 0 = wait programmed by wait1 and wait0 bits of memcom register (memcom<5:4>) bit 6-2 unimplemented: read as ? 0 ? bit 1-0 pm1:pm0: processor data memory mode select bits 11 = microcontroller mode 10 = microprocessor mode 01 = microcontroller with boot block mode 00 = extended microcontroller mode legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value after erase ?1? = bit is set ?0? = bit is cleared x = bit is unknown microprocessor mode 000000h 1fffffh external program memory external program memory 1fffffh 000000h on-chip program memory extended microcontroller mode microcontroller mode 000000h external on-chip program space execution on-chip program memory 1fffffh reads 000800h 1fffffh 0007ffh microprocessor with boot block mode 000000h on-chip program memory external program memory memory flash on-chip program memory (no access) ? 0 ?s 010000h (2) 00ffffh (2) external on-chip memory flash on-chip flash external on-chip memory flash 00bfffh (1) 00c000h (1) 00ffffh (2) 00bfffh (1) 010000h (2) 00c000h (1) note 1: pic18f6585 and pic18f8585. 2: pic18f6680 and pic18f8680.
pic18f6585/8585/6680/8680 ds30491c-page 54 ? 2004 microchip technology inc. 4.2 return address stack the return address stack allows any combination of up to 31 program calls and interrupts to occur. the pc (program counter) is pushed onto the stack when a call or rcall instruction is executed or an interrupt is acknowledged. the pc value is pulled off the stack on a return , retlw , or a retfie instruction. pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer, with the stack pointer initialized to 00000b after all resets. there is no ram associated with stack pointer 00000b. this is only a reset value. during a call type instruction causing a push onto the stack, the stack pointer is first incremented and the ram location pointed to by the stack pointer is written with the contents of the pc. during a return type instruction causing a pop from the stack, the contents of the ram location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writ- able through sfr registers. data can also be pushed to or popped from the stack, using the top-of-stack sfrs. status bits indicate if the stack pointer is at or beyond the 31 levels provided. 4.2.1 top-of-stack access the top of the stack is readable and writable. three register locations, tosu, tosh and tosl, hold the contents of the stack location pointed to by the stkptr register. this allows users to implement a software stack if necessary. after a call, rcall or interrupt, the software can read the pushed value by reading the tosu, tosh and tosl registers. these values can be placed on a user defined software stack. at return time, the software can replace the tosu, tosh and tosl and do a return. the user must disable the global interrupt enable bits during this time to prevent inadvertent stack operations. 4.2.2 return stack pointer (stkptr) the stkptr register contains the stack pointer value, the stkful (stack full) status bit, and the stkunf (stack underflow) status bits. register 4-2 shows the stkptr register. the value of the stack pointer can be 0 through 31. the stack pointer increments when values are pushed onto the stack and decrements when values are popped off the stack. at reset, the stack pointer value will be ? 0 ?. the user may read and write the stack pointer value. this feature can be used by a real-time operating system for return stack maintenance. after the pc is pushed onto the stack 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit can only be cleared in software or by a por. the action that takes place when the stack becomes full depends on the state of the stvren (stack overflow reset enable) configuration bit. refer to section 25.0 ?instruction set summary? for a description of the device configuration bits. if stvren is set (default), the 31st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to ? 0 ?. if stvren is cleared, the stkful bit will be set on the 31st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31st push and stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the pc and sets the stkunf bit while the stack pointer remains at ? 0 ?. the stkunf bit will remain set until cleared in software or a por occurs. note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken.
? 2004 microchip technology inc. ds30491c-page 55 pic18f6585/8585/6680/8680 register 4-2: stkptr register figure 4-4: return address stack and associated registers 4.2.3 push and pop instructions since the top-of-stack (tos) is readable and writable, the ability to push values onto the stack and pull values off the stack, without disturbing normal program execu- tion, is a desirable option. to push the current pc value onto the stack, a push instruction can be executed. this will increment the stack pointer and load the cur- rent pc value onto the stack. tosu, tosh and tosl can then be modified to place a return address on the stack. the ability to pull the tos value off of the stack and replace it with the value that was previously pushed onto the stack, without disturbing normal execution, is achieved by using the pop instruction. the pop instruc- tion discards the current tos by decrementing the stack pointer. the previous value pushed onto the stack then becomes the tos value. 4.2.4 stack full/underflow resets these resets are enabled by programming the stvren configuration bit. when the stvren bit is disabled, a full or underflow condition will set the appropriate stkful or stkunf bit, but not cause a device reset. when the stvren bit is enabled, a full or underflow condition will set the appropriate stkful or stkunf bit and then cause a device reset. the stkful or stkunf bits are only cleared by the user software or a por reset. r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful (1) stkunf (1) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 bit 7 stkful: stack full flag bit 1 = stack became full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit 1 = stack underflow occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp4:sp0: stack pointer location bits note 1: bit 7 and bit 6 can only be cleared in user software or by a por. legend: c = clearable bit r = readable bit u = unimplemented bit, read as ?0? w = writable bit - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack top-of-stack 000d58h tosl tosh tosu 34h 1ah 00h stkptr<4:0>
pic18f6585/8585/6680/8680 ds30491c-page 56 ? 2004 microchip technology inc. 4.3 fast register stack a ?fast interrupt return? option is available for interrupts. a fast register stack is provided for the status, wreg and bsr registers and is only one in depth. the stack is not readable or writable and is loaded with the current value of the corresponding register when the processor vectors for an interrupt. the values in the registers are then loaded back into the working regis- ters if the fast return instruction is used to return from the interrupt. a low or high priority interrupt source will push values into the stack registers. if both low and high priority interrupts are enabled, the stack registers cannot be used reliably for low priority interrupts. if a high priority interrupt occurs while servicing a low priority interrupt, the stack register values stored by the low priority interrupt will be overwritten. if high priority interrupts are not disabled during low priority interrupts, users must save the key registers in software during a low priority interrupt. if no interrupts are used, the fast register stack can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a fast call instruction must be executed. example 4-1 shows a source code example that uses the fast register stack. example 4-1: fast register stack code example 4.4 pcl, pclath and pclatu the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide. the low byte is called the pcl register; this reg- ister is readable and writable. the high byte is called the pch register. this register contains the pc<15:8> bits and is not directly readable or writable; updates to the pch register may be performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits and is not directly readable or writable; updates to the pcu register may be performed through the pclatu register. the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the lsb of the pcl is fixed to a value of ? 0 ?. the pc increments by 2 to address sequential instructions in the program memory. the call, rcall, goto and program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. the contents of pclath and pclatu will be trans- ferred to the program counter by an operation that writes pcl. similarly, the upper two bytes of the pro- gram counter will be transferred to pclath and pclatu by an operation that reads pcl. this is useful for computed offsets to the pc (see section 4.8.1 ?computed goto? ). 4.5 clocking scheme/instruction cycle the clock input (from osc1) is internally divided by four to generate four non-overlapping quadrature clocks, namely q1, q2, q3 and q4. internally, the program counter (pc) is incremented every q1, the instruction is fetched from the program memory and latched into the instruction register in q4. the instruc- tion is decoded and executed during the following q1 through q4. the clocks and instruction execution flow are shown in figure 4-5. figure 4-5: clock/ instruction cycle call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? ? return fast ;restore values saved ;in fast register stack q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc+2 pc+4 fetch inst (pc) execute inst (pc-2) fetch inst (pc+2) execute inst (pc) fetch inst (pc+4) execute inst (pc+2) internal phase clock
? 2004 microchip technology inc. ds30491c-page 57 pic18f6585/8585/6680/8680 4.6 instruction flow/pipelining an ?instruction cycle? consists of four q cycles (q1, q2, q3 and q4). the instruction fetch and execute are pipelined such that fetch takes one instruction cycle, while decode and execute takes another instruction cycle. however, due to the pipelining each instruction effectively executes in one cycle. if an instruction causes the program counter to change (e.g., goto ), then two cycles are required to complete the instruction (example 4-2). a fetch cycle begins with the program counter (pc) incrementing in q1. in the execution cycle, the fetched instruction is latched into the ?instruction register? (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3, and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). example 4-2: instruction pipeline flow 4.7 instructions in program memory the program memory is addressed in bytes. instruc- tions are stored as two bytes or four bytes in program memory. the least significant byte (lsb) of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). figure 4-6 shows an example of how instruction words are stored in the program memory. to maintain alignment with instruction boundaries, the pc increments in steps of 2 and the lsb will always read ? 0 ? (see section 4.4 ?pcl, pclath and pclatu? ). the call and goto instructions have an absolute pro- gram memory address embedded into the instruction. since instructions are always stored on word bound- aries, the data contained in the instruction is a word address. the word address is written to pc<20:1> which accesses the desired byte address in program memory. instruction #2 in figure 4-6 shows how the instruction ? goto 000006h ? is encoded in the program memory. program branch instructions which encode a relative address offset operate in the same manner. the offset value stored in a branch instruction repre- sents the number of single-word instructions that the pc will be offset by. section 25.0 ?instruction set summary? provides further details of the instruction set. figure 4-6: instructions in program memory all instructions are single cycle except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, 3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1 word address lsb = 1 lsb = 0 program memory byte locations 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 000006h 0efh 03h 00000ah 0f0h 00h 00000ch instruction 3: movff 123h, 456h 0c1h 23h 00000eh 0f4h 56h 000010h 000012h 000014h
pic18f6585/8585/6680/8680 ds30491c-page 58 ? 2004 microchip technology inc. 4.7.1 two-word instructions the pic18f6585/8585/6680/8680 devices have four two-word instructions: movff, call, goto and lfsr . the second word of these instructions has the 4 msbs set to ? 1 ?s and is a special kind of nop instruction. the lower 12 bits of the second word contain data to be used by the instruction. if the first word of the instruc- tion is executed, the data in the second word is accessed. if the second word of the instruction is exe- cuted by itself (first word was skipped), it will execute as a nop . this action is necessary when the two-word instruction is preceded by a conditional instruction that changes the pc. a program example that demon- strates this concept is shown in example 4-3. refer to section 25.0 ?instruction set summary? for further details of the instruction set. example 4-3: two-word instructions 4.8 look-up tables look-up tables are implemented two ways. these are:  computed goto  table reads 4.8.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). a look-up table can be formed with an addwf pcl instruction and a group of retlw 0xnn instructions. wreg is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next instruction executed will be one of the retlw 0xnn instructions that returns the value 0xnn to the calling function. the offset value (value in wreg) specifies the number of bytes that the program counter should advance. in this method, only one data byte may be stored in each instruction location and room on the return address stack is required. 4.8.2 table reads/table writes a better method of storing data in program memory allows 2 bytes of data to be stored in each instruction location. look-up table data may be stored 2 bytes per program word by using table reads and writes. the table pointer (tblptr) specifies the byte address and the table latch (tablat) contains the data that is read from, or written to program memory. data is transferred to/from program memory, one byte at a time. a description of the table read/table write operation is shown in section 5.0 ?flash program memory? . case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, execute 2-word instruction 1111 0100 0101 0110 ; 2nd operand holds address of reg2 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes 1111 0100 0101 0110 ; 2nd operand becomes nop 0010 0100 0000 0000 addwf reg3 ; continue code
? 2004 microchip technology inc. ds30491c-page 59 pic18f6585/8585/6680/8680 4.9 data memory organization the data memory is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. figure 4-7 shows the data memory organization for the pic18f6585/8585/6680/8680 devices. the data memory map is divided into 16 banks that contain 256 bytes each. the lower 4 bits of the bank select register (bsr<3:0>) select which bank will be accessed. the upper 4 bits for the bsr are not implemented. the data memory contains special function registers (sfr) and general purpose registers (gpr). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratch pad operations in the user?s appli- cation. the sfrs start at the last location of bank 15 (0fffh) and extend downwards. any remaining space beyond the sfrs in the bank may be implemented as gprs. gprs start at the first location of bank 0 and grow upwards. any read of an unimplemented location will read as ? 0 ?s. the entire data memory may be accessed directly or indirectly. direct addressing may require the use of the bsr register. indirect addressing requires the use of a file select register (fsrn) and a corresponding indi- rect file operand (indfn). each fsr holds a 12-bit address value that can be used to access any location in the data memory map without banking. the instruction set and architecture allow operations across all banks. this may be accomplished by indirect addressing or by the use of the movff instruction. the movff instruction is a two-word/two-cycle instruction that moves a value from one register to another. to ensure that commonly used registers (sfrs and select gprs) can be accessed in a single cycle regard- less of the current bsr values, an access bank is implemented. a segment of bank 0 and a segment of bank 15 comprise the access ram. section 4.10 ?access bank? provides a detailed description of the access ram. 4.9.1 general purpose register file the register file can be accessed either directly or indi- rectly. indirect addressing operates using a file select register and corresponding indirect file operand. the operation of indirect addressing is shown in section 4.12 ?indirect addressing, indf and fsr registers? . enhanced mcu devices may have banked memory in the gpr area. gprs are not initialized by a power-on reset and are unchanged on all other resets. data ram is available for use as general purpose regis- ters by all instructions. the top section of bank 15 (0f60h to 0fffh) contains sfrs. all other banks of data memory contain gpr register s, starting with bank 0. 4.9.2 special function registers the special function registers (sfrs) are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. a list of these registers is given in table 4-2 and table 4-3. the sfrs can be classified into two sets: those asso- ciated with the ?core? function and those related to the peripheral functions. those registers related to the ?core? are described in this section, while those related to the operation of the peripheral features are described in the section of that peripheral feature. the sfrs are typically distributed among the peripherals whose functions they control. the unused sfr locations are unimplemented and read as ? 0 ?s. the addresses for the sfrs are listed in table 4-2.
pic18f6585/8585/6680/8680 ds30491c-page 60 ? 2004 microchip technology inc. figure 4-7: data memory map for pic18fxx80/xx85 devices bank 0 bank 1 bank 12 bank 15 data memory map bsr<3:0> = 0000 = 0001 = 1110 = 1111 060h 05fh f60h fffh 00h 5fh 60h ffh access bank when a = 0 , the bsr is ignored and the access bank is used. the first 96 bytes are general purpose ram (from bank 0). the second 160 bytes are special function registers (from bank 15). when a = 1 , the bsr is used to specify the ram location that the instruction uses. bank 4 bank 3 bank 2 f5fh f00h effh 3ffh 300h 2ffh 200h 1ffh 100h 0ffh 000h = 0011 = 0010 access ram ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h gprs gprs gprs gprs sfrs can sfrs access ram high access ram low bank 14 gprs can sfrs bank 5 to 4ffh 400h dffh 500h e00h = 0100 (sfrs) gprs can sfrs d00h cffh bank 13 = 1101
? 2004 microchip technology inc. ds30491c-page 61 pic18f6585/8585/6680/8680 table 4-2: special function register map address name address name address name address name fffh tosu fdfh indf2 (3) fbfh ccpr1h f9fh ipr1 ffeh tosh fdeh postinc2 (3) fbeh ccpr1l f9eh pir1 ffdh tosl fddh postdec2 (3) fbdh ccp1con f9dh pie1 ffch stkptr fdch preinc2 (3) fbch ccpr2h f9ch memcon (2) ffbh pclatu fdbh plusw2 (3) fbbh ccpr2l f9bh ? (1) ffah pclath fdah fsr2h fbah ccp2con f9ah trisj (2) ff9h pcl fd9h fsr2l fb9h ? (1) f99h trish (2) ff8h tblptru fd8h status fb8h ? (1) f98h trisg ff7h tblptrh fd7h tmr0h fb7h ? (1) f97h trisf ff6h tblptrl fd6h tmr0l fb6h eccp1as f96h trise ff5h tablat fd5h t0con fb5h cvrcon f95h trisd ff4h prodh fd4h ? (1) fb4h cmcon f94h trisc ff3h prodl fd3h osccon fb3h tmr3h f93h trisb ff2h intcon fd2h lvdcon fb2h tmr3l f92h trisa ff1h intcon2 fd1h wdtcon fb1h t3con f91h latj (2) ff0h intcon3 fd0h rcon fb0h pspcon f90h lath (2) fefh indf0 (3) fcfh tmr1h fafh spbrg f8fh latg feeh postinc0 (3) fceh tmr1l faeh rcreg f8eh latf fedh postdec0 (3) fcdh t1con fadh txreg f8dh late fech preinc0 (3) fcch tmr2 fach txsta f8ch latd febh plusw0 (3) fcbh pr2 fabh rcsta f8bh latc feah fsr0h fcah t2con faah eeadrh f8ah latb fe9h fsr0l fc9h sspbuf fa9h eeadr f89h lata fe8h wreg fc8h sspadd fa8h eedata f88h portj (2) fe7h indf1 (3) fc7h sspstat fa7h eecon2 f87h porth (2) fe6h postinc1 (3) fc6h sspcon1 fa6h eecon1 f86h portg fe5h postdec1 (3) fc5h sspcon2 fa5h ipr3 f85h portf fe4h preinc1 (3) fc4h adresh fa4h pir3 f84h porte fe3h plusw1 (3) fc3h adresl fa3h pie3 f83h portd fe2h fsr1h fc2h adcon0 fa2h ipr2 f82h portc fe1h fsr1l fc1h adcon1 fa1h pir2 f81h portb fe0h bsr fc0h adcon2 fa0h pie2 f80h porta note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
pic18f6585/8585/6680/8680 ds30491c-page 62 ? 2004 microchip technology inc. address name address name address name address name f7fh spbrgh f5fh cancon_ro0 f3fh cancon_ro2 f1fh rxm1eidl f7eh baudcon f5eh canstat_ro0 f3eh canstat_ro2 f1eh rxm1eidh f7dh ? (1) f5dh rxb1d7 f3dh txb1d7 f1dh rxm1sidl f7ch ? (1) f5ch rxb1d6 f3ch txb1d6 f1ch rxm1sidh f7bh ? (1) f5bh rxb1d5 f3bh txb1d5 f1bh rxm0eidl f7ah ? (1) f5ah rxb1d4 f3ah txb1d4 f1ah rxm0eidh f79h eccp1del f59h rxb1d3 f39h txb1d3 f19h rxm0sidl f78h ? (1) f58h rxb1d2 f38h txb1d2 f18h rxm0sidh f77h ecancon f57h rxb1d1 f37h txb1d1 f17h rxf5eidl f76h txerrcnt f56h rxb1d0 f36h txb1d0 f16h rxf5eidh f75h rxerrcnt f55h rxb1dlc f35h txb1dlc f15h rxf5sidl f74h comstat f54h rxb1eidl f34h txb1eidl f14h rxf5sidh f73h ciocon f53h rxb1eidh f33h txb1eidh f13h rxf4eidl f72h brgcon3 f52h rxb1sidl f32h txb1sidl f12h rxf4eidh f71h brgcon2 f51h rxb1sidh f31h txb1sidh f11h rxf4sidl f70h brgcon1 f50h rxb1con f30h txb1con f10h rxf4sidh f6fh cancon f4fh cancon_ro1 f2fh cancon_ro3 f0fh rxf3eidl f6eh canstat f4eh canstat_ro1 f2eh canstat_ro3 f0eh rxf3eidh f6dh rxb0d7 f4dh txb0d7 f2dh txb2d7 f0dh rxf3sidl f6ch rxb0d6 f4ch txb0d6 f2ch txb2d6 f0ch rxf3sidh f6bh rxb0d5 f4bh txb0d5 f2 bh txb2d5 f0bh rxf2eidl f6ah rxb0d4 f4ah txb0d4 f2 ah txb2d4 f0ah rxf2eidh f69h rxb0d3 f49h txb0d3 f29h txb2d3 f09h rxf2sidl f68h rxb0d2 f48h txb0d2 f28h txb2d2 f08h rxf2sidh f67h rxb0d1 f47h txb0d1 f27h txb2d1 f07h rxf1eidl f66h rxb0d0 f46h txb0d0 f26h txb2d0 f06h rxf1eidh f65h rxb0dlc f45h txb0dlc f25h txb2dlc f05h rxf1sidl f64h rxb0eidl f44h txb0eidl f24h txb2eidl f04h rxf1sidh f63h rxb0eidh f43h txb0eidh f23h txb2eidh f03h rxf0eidl f62h rxb0sidl f42h txb0sidl f22h txb2sidl f02h rxf0eidh f61h rxb0sidh f41h txb0sidh f21h txb2sidh f01h rxf0sidl f60h rxb0con f40h txb0con f20h txb2con f00h rxf0sidh table 4-2: special function register map (continued) note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
? 2004 microchip technology inc. ds30491c-page 63 pic18f6585/8585/6680/8680 address name address name address name address name effh ? (1) edfh ? (1) ebfh ? (1) e9fh ? (1) efeh ? (1) edeh ? (1) ebeh ? (1) e9eh ? (1) efdh ? (1) eddh ? (1) ebdh ? (1) e9dh ? (1) efch ? (1) edch ? (1) ebch ? (1) e9ch ? (1) efbh ? (1) edbh ? (1) ebbh ? (1) e9bh ? (1) efah ? (1) edah ? (1) ebah ? (1) e9ah ? (1) ef9h ? (1) ed9h ? (1) eb9h ? (1) e99h ? (1) ef8h ? (1) ed8h ? (1) eb8h ? (1) e98h ? (1) ef7h ? (1) ed7h ? (1) eb7h ? (1) e97h ? (1) ef6h ? (1) ed6h ? (1) eb6h ? (1) e96h ? (1) ef5h ? (1) ed5h ? (1) eb5h ? (1) e95h ? (1) ef4h ? (1) ed4h ? (1) eb4h ? (1) e94h ? (1) ef3h ? (1) ed3h ? (1) eb3h ? (1) e93h ? (1) ef2h ? (1) ed2h ? (1) eb2h ? (1) e92h ? (1) ef1h ? (1) ed1h ? (1) eb1h ? (1) e91h ? (1) ef0h ? (1) ed0h ? (1) eb0h ? (1) e90h ? (1) eefh ? (1) ecfh ? (1) eafh ? (1) e8fh ? (1) eeeh ? (1) eceh ? (1) eaeh ? (1) e8eh ? (1) eedh ? (1) ecdh ? (1) eadh ? (1) e8dh ? (1) eech ? (1) ecch ? (1) each ? (1) e8ch ? (1) eebh ? (1) ecbh ? (1) eabh ? (1) e8bh ? (1) eeah ? (1) ecah ? (1) eaah ? (1) e8ah ? (1) ee9h ? (1) ec9h ? (1) ea9h ? (1) e89h ? (1) ee8h ? (1) ec8h ? (1) ea8h ? (1) e88h ? (1) ee7h ? (1) ec7h ? (1) ea7h ? (1) e87h ? (1) ee6h ? (1) ec6h ? (1) ea6h ? (1) e86h ? (1) ee5h ? (1) ec5h ? (1) ea5h ? (1) e85h ? (1) ee4h ? (1) ec4h ? (1) ea4h ? (1) e84h ? (1) ee3h ? (1) ec3h ? (1) ea3h ? (1) e83h ? (1) ee2h ? (1) ec2h ? (1) ea2h ? (1) e82h ? (1) ee1h ? (1) ec1h ? (1) ea1h ? (1) e81h ? (1) ee0h ? (1) ec0h ? (1) ea0h ? (1) e80h ? (1) table 4-2: special function register map (continued) note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
pic18f6585/8585/6680/8680 ds30491c-page 64 ? 2004 microchip technology inc. address name address name address name address name e7fh cancon_ro4 e5fh cancon_ro6 e3fh cancon_ro8 e1fh ? (1) e7eh canstat_ro4 e5eh canstat_ro6 e3eh canstat_ro8 e1eh ? (1) e7dh b5d7 e5dh b3d7 e3dh b1d7 e1dh ? (1) e7ch b5d6 e5ch b3d6 e3ch b1d6 e1ch ? (1) e7bh b5d5 e5bh b3d5 e3bh b1d5 e1bh ? (1) e7ah b5d4 e5ah b3d4 e3ah b1d4 e1ah ? (1) e79h b5d3 e59h b3d3 e39h b1d3 e19h ? (1) e78h b5d2 e58h b3d2 e38h b1d2 e18h ? (1) e77h b5d1 e57h b3d1 e37h b1d1 e17h ? (1) e76h b5d0 e56h b3d0 e36h b1d0 e16h ? (1) e75h b5dlc e55h b3dlc e35h b1dlc e15h ? (1) e74h b5eidl e54h b3eidl e34h b1eidl e14h ? (1) e73h b5eidh e53h b3eidh e33h b1eidh e13h ? (1) e72h b5sidl e52h b3sidl e32h b1sidl e12h ? (1) e71h b5sidh e51h b3sidh e31h b1sidh e11h ? (1) e70h b5con e50h b3con e30h b1con e10h ? (1) e6fh cancon_ro5 e4fh cancon_ro7 e2fh cancon_ro9 e0fh ? (1) e6eh canstat_ro5 e4eh canstat_ro7 e2eh canstat_ro9 e0eh ? (1) e6dh b4d7 e4dh b2d7 e2dh b0d7 e0dh ? (1) e6ch b4d6 e4ch b2d6 e2ch b0d6 e0ch ? (1) e6bh b4d5 e4bh b2d5 e2bh b0d5 e0bh ? (1) e6ah b4d4 e4ah b2d4 e2ah b0d4 e0ah ? (1) e69h b4d3 e49h b2d3 e29h b0d3 e09h ? (1) e68h b4d2 e48h b2d2 e28h b0d2 e08h ? (1) e67h b4d1 e47h b2d1 e27h b0d1 e07h ? (1) e66h b4d0 e46h b2d0 e26h b0d0 e06h ? (1) e65h b4dlc e45h b2dlc e25h b0dlc e05h ? (1) e64h b4eidl e44h b2eidl e24h b0eidl e04h ? (1) e63h b4eidh e43h b2eidh e23h b0eidh e03h ? (1) e62h b4sidl e42h b2sidl e22h b0sidl e02h ? (1) e61h b4sidh e41h b2sidh e21h b0sidh e01h ? (1) e60h b4con e40h b2con e20h b0con e00h ? (1) table 4-2: special function register map (continued) note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
? 2004 microchip technology inc. ds30491c-page 65 pic18f6585/8585/6680/8680 address name address name address name address name dffh ? (1) ddfh ? (1) dbfh ? (1) d9fh ? (1) dfeh ? (1) ddeh ? (1) dbeh ? (1) d9eh ? (1) dfdh ? (1) dddh ? (1) dbdh ? (1) d9dh ? (1) dfch txbie ddch ? (1) dbch ? (1) d9ch ? (1) dfbh ? (1) ddbh ? (1) dbbh ? (1) d9bh ? (1) dfah bie0 ddah ? (1) dbah ? (1) d9ah ? (1) df9h ? (1) dd9h ? (1) db9h ? (1) d99h ? (1) df8h bsel0 dd8h sdflc db8h ? (1) d98h ? (1) df7h ? (1) dd7h ? (1) db7h ? (1) d97h ? (1) df6h ? (1) dd6h ? (1) db6h ? (1) d96h ? (1) df5h ? (1) dd5h rxfcon1 db5h ? (1) d95h ? (1) df4h ? (1) dd4h rxfcon0 db4h ? (1) d94h ? (1) df3h msel3 dd3h ? (1) db3h ? (1) d93h rxf15eidl df2h msel2 dd2h ? (1) db2h ? (1) d92h rxf15eidh df1h msel1 dd1h ? (1) db1h ? (1) d91h rxf15sidl df0h msel0 dd0h ? (1) db0h ? (1) d90h rxf15sidh defh ? (1) dcfh ? (1) dafh ? (1) d8fh ? (1) deeh ? (1) dceh ? (1) daeh ? (1) d8eh ? (1) dedh ? (1) dcdh ? (1) dadh ? (1) d8dh ? (1) dech ? (1) dcch ? (1) dach ? (1) d8ch ? (1) debh ? (1) dcbh ? (1) dabh ? (1) d8bh rxf14eidl deah ? (1) dcah ? (1) daah ? (1) d8ah rxf14eidh de9h ? (1) dc9h ? (1) da9h ? (1) d89h rxf14sidl de8h ? (1) dc8h ? (1) da8h ? (1) d88h rxf14sidh de7h rxfbcon7 dc7h ? (1) da7h ? (1) d87h rxf13eidl de6h rxfbcon6 dc6h ? (1) da6h ? (1) d86h rxf13eidh de5h rxfbcon5 dc5h ? (1) da5h ? (1) d85h rxf13sidl de4h rxfbcon4 dc4h ? (1) da4h ? (1) d84h rxf13sidh de3h rxfbcon3 dc3h ? (1) da3h ? (1) d83h rxf12eidl de2h rxfbcon2 dc2h ? (1) da2h ? (1) d82h rxf12eidh de1h rxfbcon1 dc1h ? (1) da1h ? (1) d81h rxf12sidl de0h rxfbcon0 dc0h ? (1) da0h ? (1) d80h rxf12sidh table 4-2: special function register map (continued) note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
pic18f6585/8585/6680/8680 ds30491c-page 66 ? 2004 microchip technology inc. address name address name address name address name d7fh ? (1) d7eh ? (1) d7dh ? (1) d7ch ? (1) d7bh rxf11eidl d7ah rxf11eidh d79h rxf11sidl d78h rxf11sidh d77h rxf10eidl d76h rxf10eidh d75h rxf10sidl d74h rxf10sidh d73h rxf9eidl d72h rxf9eidh d71h rxf9sidl d70h rxf9sidh d6fh ? (1) d6eh ? (1) d6dh ? (1) d6ch ? (1) d6bh rxf8eidl d6ah rxf8eidh d69h rxf8sidl d68h rxf8sidh d67h rxf7eidl d66h rxf7eidh d65h rxf7sidl d64h rxf7sidh d63h rxf6eidl d62h rxf6eidh d61h rxf6sidl d60h rxf6sidh table 4-2: special function register map (continued) note 1: unimplemented registers are read as ? 0 ?. 2: this register is not available on pic18f6x8x devices. 3: this is not a physical register.
? 2004 microchip technology inc. ds30491c-page 67 pic18f6585/8585/6680/8680 table 4-3: register file summary file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: tosu ? ? ? top-of-stack upper byte (tos<20:16>) ---0 0000 36, 54 tosh top-of-stack high byte (tos<15:8>) 0000 0000 36, 54 tosl top-of-stack low byte (tos<7:0>) 0000 0000 36, 54 stkptr stkful stkunf ? return stack pointer 00-0 0000 36, 55 pclatu ? ? bit 21 holding register for pc<20:16> --00 0000 36, 56 pclath holding register for pc<15:8> 0000 0000 36, 56 pcl pc low byte (pc<7:0>) 0000 0000 36, 56 tblptru ? ?bit 21 (2) program memory table pointer upper byte (tblptr<20:16>) --00 0000 36, 86 tblptrh program memory table pointer high byte (tblptr<15:8>) 0000 0000 36, 86 tblptrl program memory table pointer low byte (tblptr<7:0>) 0000 0000 36, 86 tablat program memory table latch 0000 0000 36, 86 prodh product register high byte xxxx xxxx 36, 107 prodl product register low byte xxxx xxxx 36, 107 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 36, 111 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 1111 1111 36, 112 intcon3 int2ip int1ip int3ie int 2ie int1ie int3if int2if int1if 1100 0000 36, 113 indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) n/a 79 postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) n/a 79 postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) n/a 79 preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) n/a 79 plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) ? value of fsr0 offset by value in wreg n/a 79 fsr0h ? ? ? ? indirect data memory address pointer 0 high byte ---- 0000 36, 79 fsr0l indirect data memory address pointer 0 low byte xxxx xxxx 36, 79 wreg working register xxxx xxxx 36 indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) n/a 79 postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) n/a 79 postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) n/a 79 preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) n/a 79 plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) ? value of fsr1 offset by value in wreg n/a 79 fsr1h ? ? ? ? indirect data memory address pointer 1 high byte ---- 0000 37, 79 fsr1l indirect data memory address pointer 1 low byte xxxx xxxx 37, 79 bsr ? ? ? ? bank select register ---- 0000 37, 78 indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) n/a 79 postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) n/a 79 postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) n/a 79 preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) n/a 79 plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) ? value of fsr2 offset by value in wreg n/a 79 fsr2h ? ? ? ? indirect data memory address pointer 2 high byte ---- 0000 37, 79 fsr2l indirect data memory address pointer 2 low byte xxxx xxxx 37, 79 legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 68 ? 2004 microchip technology inc. status ? ? ?nov zdcc ---x xxxx 37, 81 tmr0h timer0 register high byte 0000 0000 37, 157 tmr0l timer0 register low byte xxxx xxxx 37, 157 t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 1111 1111 37, 155 osccon ? ? ? ? lock pllen scs1 scs ---- 0000 27, 37 lvdcon ? ? irvst lvden lvdl3 lvdl2 lvdl1 lvdl0 --00 0101 37, 271 wdtcon ? ? ? ? ? ? ?swdte ---- ---0 37, 355 rcon ipen ? ?ri to pd por bor 0--1 11qq 37, 82, 123 tmr1h timer1 register high byte xxxx xxxx 37, 159 tmr1l timer1 register low byte xxxx xxxx 37, 159 t1con rd16 ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0-00 0000 37, 159 tmr2 timer2 register 0000 0000 37, 162 pr2 timer2 period register 1111 1111 37, 163 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 -000 0000 37, 162 sspbuf ssp receive buffer/transmit register xxxx xxxx 37, 189 sspadd ssp address register in i 2 c slave mode. ssp baud rate reload register in i 2 c master mode. 0000 0000 37, 198 sspstat smp cke d/a psr/w ua bf 0000 0000 37, 199 sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 37, 191 sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 37, 201 adresh a/d result register high byte xxxx xxxx 38, 257 adresl a/d result register low byte xxxx xxxx 38, 257 adcon0 ? ? chs3 chs2 chs1 chs0 go/done adon --00 0000 38, 249 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0000 38, 257 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 0-00 0000 38, 251 ccpr1h enhanced capture/compare/pwm register 1 high byte xxxx xxxx 38, 173 ccpr1l enhanced capture/compare/pwm register 1 low byte xxxx xxxx 38, 172 ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 38, 172 ccpr2h capture/compare/pwm register 2 high byte xxxx xxxx 38, 172 ccpr2l capture/compare/pwm register 2 low byte xxxx xxxx 38, 172 ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 38, 172 eccp1as eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 0000 0000 38, 172 cvrcon cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 0000 38, 265 cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 38, 259 tmr3h timer3 register high byte xxxx xxxx 38, 164 tmr3l timer3 register low byte xxxx xxxx 38, 164 t3con rd16 t3ccp2 t3ckps1 t3ckps0 t3ccp1 t3sync tmr3cs tmr3on 0000 0000 38, 164 pspcon ibf obf ibov pspmode ? ? ? ? 0000 ---- 38, 153 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 69 pic18f6585/8585/6680/8680 spbrg usart baud rate generator 0000 0000 38, 239 rcreg usart receive register 0000 0000 38, 241 txreg usart transmit register 0000 0000 38, 239 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 38, 230 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 38, 231 eeadrh ? ? ? ? ? ? ee adr register high ---- --00 38, 105 eeadr data eeprom address register 0000 0000 38, 105 eedata data eeprom data register 0000 0000 38, 105 eecon2 data eeprom control register 2 (not a physical register) ---- ---- 38, 105 eecon1 eepgd cfgs ? free wrerr wren wr rd 00-0 x000 38, 102 ipr3 irxip wakip errip txb2ip/ txbnip txb1ip txb0ip rxb1ip/ rxbnip rxb0ip/ fifowmip 1111 1111 39, 122 pir3 irxif wakif errif txb2if/ txbnif txb1if txb0if rxb1if/ rxbnif rxb0if/ fifowmif 0000 0000 39, 116 pie3 irxie wakie errie txb2ie/ txbnie txb1ie txb0ie rxb1ie/ rxbnie rxb0ie/ fifowmie 0000 0000 39, 119 ipr2 ?cmip ? eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 39, 121 pir2 ?cmif ? eeif bclif lvdif tmr3if ccp2if -0-0 0000 39, 115 pie2 ?cmie ? eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 39, 118 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 0111 1111 39, 120 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 39, 114 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 39, 117 memcon (3) ebdis ?wait1wait0 ? ?wm1wm0 0-00 --00 39, 94 trisj (3) data direction control register for portj 1111 1111 39, 151 trish (3) data direction control register for porth 1111 1111 39, 148 trisg ? ? ? data direction control register for portg ---1 1111 39, 145 trisf data direction control register for portf 1111 1111 39, 141 trise data direction control register for porte 1111 1111 39, 138 trisd data direction control register for portd 1111 1111 39, 135 trisc data direction control register for portc 1111 1111 39, 131 trisb data direction control register for portb 1111 1111 39, 128 trisa ?trisa6 (1) data direction control register for porta -111 1111 39, 125 latj (3) read portj data latch, write portj data latch xxxx xxxx 39, 151 lath (3) read porth data latch, write porth data latch xxxx xxxx 39, 148 latg ? ? ? read portg data latch, write portg data latch ---x xxxx 39, 145 latf read portf data latch, write portf data latch xxxx xxxx 39, 141 late read porte data latch, write porte data latch xxxx xxxx 39, 138 latd read portd data latch, write portd data latch xxxx xxxx 39, 133 latc read portc data latch, write portc data latch xxxx xxxx 39, 131 latb read portb data latch, write portb data latch xxxx xxxx 39, 128 lata ?lata6 (1) read porta data latch, write porta data latch (1) -xxx xxxx 39, 125 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 70 ? 2004 microchip technology inc. portj (3) read portj pins, write portj data latch xxxx xxxx 40, 151 porth (3) read porth pins, write porth data latch xxxx xxxx 40, 148 portg ? ?rg5 (6) read portg pins, write portg data latch --0x xxxx 40, 145 portf read portf pins, write portf data latch xxxx xxxx 40, 141 porte read porte pins, write porte data latch xxxx xxxx 40, 136 portd read portd pins, write portd data latch xxxx xxxx 40, 133 portc read portc pins, write portc data latch xxxx xxxx 40, 131 portb read portb pins, write portb data latch xxxx xxxx 40, 128 porta ?ra6 (1) read porta pins, write porta data latch (1) -x0x 0000 40, 125 spbrgh enhanced usart baud rate generator high byte 0000 0000 40, 233 baudcon ? rcidl ? sckp brg16 ? wue abden -1-0 0-00 40, 233 eccp1del prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 0000 0000 40, 187 txerrcnt tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 0000 0000 40, 288 rxerrcnt rec7 rec6 rec5 rec4 rec3 rec2 rec1 rec0 0000 0000 40, 296 comstat mode 0 rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn 0000 0000 40, 284 comstat mode 1 ? rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn -000 0000 40, 284 comstat mode 2 fifoempty rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn 0000 0000 40, 284 ciocon tx2src tx2en endrhi cancap ? ? ? ? 0000 ---- 40, 318 brgcon3 wakdis wakfil ? ? ? seg2ph2 seg2ph1 seg2ph0 00-- -000 40, 317 brgcon2 seg2pht sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 0000 0000 40, 317 brgcon1 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 0000 0000 40, 317 cancon mode 0 reqop2 reqop1 reqop0 abat win2 win1 win0 ? 1000 000- 40, 239 cancon mode 1 reqop2 reqop1 reqop0 abat ? ? ? ? 1000 ---- 40, 239 cancon mode 2 reqop2 reqop1 reqop0 abat fp3 fp2 fp1 fp0 1000 0000 40, 239 canstat mode 0 opmode2 opmode1 opmode0 ? icode2 icode1 icode0 ? 000- 0000 40, 239 canstat modes 0, 1 opmode2 opmode1 opmode0 eicode4 eicode3 eicode2 eicode1 eicode0 0000 0000 40, 239 ecancon mdsel1 mdsel0 fifowm ewin4 ewin3 ewin2 ewin1 ewin0 0001 0000 40, 323 rxb0d7 rxb0d77 rxb0d76 rxb0d75 rxb0d74 rxb0d73 rxb0d72 rxb0d71 rxb0d70 xxxx xxxx 40, 230 rxb0d6 rxb0d67 rxb0d66 rxb0d65 rxb0d64 rxb0d63 rxb0d62 rxb0d61 rxb0d60 xxxx xxxx 40, 230 rxb0d5 rxb0d57 rxb0d56 rxb0d55 rxb0d54 rxb0d53 rxb0d52 rxb0d51 rxb0d50 xxxx xxxx 40, 230 rxb0d4 rxb0d47 rxb0d46 rxb0d45 rxb0d44 rxb0d43 rxb0d42 rxb0d41 rxb0d40 xxxx xxxx 40, 230 rxb0d3 rxb0d37 rxb0d36 rxb0d35 rxb0d34 rxb0d33 rxb0d32 rxb0d31 rxb0d30 xxxx xxxx 40, 230 rxb0d2 rxb0d27 rxb0d26 rxb0d25 rxb0d24 rxb0d23 rxb0d22 rxb0d21 rxb0d20 xxxx xxxx 40, 230 rxb0d1 rxb0d17 rxb0d16 rxb0d15 rxb0d14 rxb0d13 rxb0d12 rxb0d11 rxb0d10 xxxx xxxx 40, 230 rxb0d0 rxb0d07 rxb0d06 rxb0d05 rxb0d04 rxb0d03 rxb0d02 rxb0d01 rxb0d00 xxxx xxxx 40, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 71 pic18f6585/8585/6680/8680 rxb0dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 40, 230 rxb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 41, 230 rxb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 41, 230 rxb0sidl sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 41, 230 rxb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 41, 230 rxb0con mode 0 rxful rxm1 rxm0 (4) ? (4) rxrtrr0 (4) rxb0dben (4) jtoff (4) filhit0 (4) 000- 0000 41, 230 rxb0con mode 1, 2 rxful rxm1 rtrr0 (4) filhit4 (4) filhit3 (4) filhit2 (4) filhit1 (4) filhit0 (4) 0000 0000 41, 230 rxb1d7 rxb1d77 rxb1d76 rxb1d75 rxb1d74 rxb1d73 rxb1d72 rxb1d71 rxb1d70 xxxx xxxx 41, 230 rxb1d6 rxb1d67 rxb1d66 rxb1d65 rxb1d64 rxb1d63 rxb1d62 rxb1d61 rxb1d60 xxxx xxxx 41, 230 rxb1d5 rxb1d57 rxb1d56 rxb1d55 rxb1d54 rxb1d53 rxb1d52 rxb1d51 rxb1d50 xxxx xxxx 41, 230 rxb1d4 rxb1d47 rxb1d46 rxb1d45 rxb1d44 rxb1d43 rxb1d42 rxb1d41 rxb1d40 xxxx xxxx 41, 230 rxb1d3 rxb1d37 rxb1d36 rxb1d35 rxb1d34 rxb1d33 rxb1d32 rxb1d31 rxb1d30 xxxx xxxx 41, 230 rxb1d2 rxb1d27 rxb1d26 rxb1d25 rxb1d24 rxb1d23 rxb1d22 rxb1d21 rxb1d20 xxxx xxxx 41, 230 rxb1d1 rxb1d17 rxb1d16 rxb1d15 rxb1d14 rxb1d13 rxb1d12 rxb1d11 rxb1d10 xxxx xxxx 41, 230 rxb1d0 rxb1d07 rxb1d06 rxb1d05 rxb1d04 rxb1d03 rxb1d02 rxb1d01 rxb1d00 xxxx xxxx 41, 230 rxb1dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 41, 230 rxb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 41, 230 rxb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 41, 230 rxb1sidl sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 41, 230 rxb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 41, 230 rxb1con mode 0 rxful rxm1 rxm0 (4) ? (4) rxrtrr0 (4) filhit2 (4) filhit1 (4) filhit0 (4) 000- 0000 41, 230 rxb1con mode 1, 2 rxful rxm1 rtrro (4) filhit4 (4) filhit3 (4) filhit2 (4) filhit1 (4) filhit0 (4) 0000 0000 41, 230 txb0d7 txb0d77 txb0d76 txb0d75 txb0d74 txb0d73 txb0d72 txb0d71 txb0d70 xxxx xxxx 41, 230 txb0d6 txb0d67 txb0d66 txb0d65 txb0d64 txb0d63 txb0d62 txb0d61 txb0d60 xxxx xxxx 41, 230 txb0d5 txb0d57 txb0d56 txb0d55 txb0d54 txb0d53 txb0d52 txb0d51 txb0d50 xxxx xxxx 41, 230 txb0d4 txb0d47 txb0d46 txb0d45 txb0d44 txb0d43 txb0d42 txb0d41 txb0d40 xxxx xxxx 41, 230 txb0d3 txb0d37 txb0d36 txb0d35 txb0d34 txb0d33 txb0d32 txb0d31 txb0d30 xxxx xxxx 41, 230 txb0d2 txb0d27 txb0d26 txb0d25 txb0d24 txb0d23 txb0d22 txb0d21 txb0d20 xxxx xxxx 41, 230 txb0d1 txb0d17 txb0d16 txb0d15 txb0d14 txb0d13 txb0d12 txb0d11 txb0d10 xxxx xxxx 41, 230 txb0d0 txb0d07 txb0d06 txb0d05 txb0d04 txb0d03 txb0d02 txb0d01 txb0d00 xxxx xxxx 41, 230 txb0dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 41, 230 txb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 41, 230 txb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 41, 230 txb0sidl sid2 sid1 sid0 ?exide ?eid17eid16 xx-x x-xx 41, 230 txb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 42, 230 txb0con mode 0 ? txabt txlarb txerr txreq ? txpri1 txpri0 -000 0-00 42, 230 txb0con mode 1, 2 txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 42, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 72 ? 2004 microchip technology inc. txb1d7 txb1d77 txb1d76 txb1d75 txb1d74 txb1d73 txb1d72 txb1d71 txb1d70 xxxx xxxx 42, 230 txb1d6 txb1d67 txb1d66 txb1d65 txb1d64 txb1d63 txb1d62 txb1d61 txb1d60 xxxx xxxx 42, 230 txb1d5 txb1d57 txb1d56 txb1d55 txb1d54 txb1d53 txb1d52 txb1d51 txb1d50 xxxx xxxx 42, 230 txb1d4 txb1d47 txb1d46 txb1d45 txb1d44 txb1d43 txb1d42 txb1d41 txb1d40 xxxx xxxx 42, 230 txb1d3 txb1d37 txb1d36 txb1d35 txb1d34 txb1d33 txb1d32 txb1d31 txb1d30 xxxx xxxx 42, 230 txb1d2 txb1d27 txb1d26 txb1d25 txb1d24 txb1d23 txb1d22 txb1d21 txb1d20 xxxx xxxx 42, 230 txb1d1 txb1d17 txb1d16 txb1d15 txb1d14 txb1d13 txb1d12 txb1d11 txb1d10 xxxx xxxx 42, 230 txb1d0 txb1d07 txb1d06 txb1d05 txb1d04 txb1d03 txb1d02 txb1d01 txb1d00 xxxx xxxx 42, 230 txb1dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 42, 230 txb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 42, 230 txb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 42, 230 txb1sidl sid2 sid1 sid0 ?exide ?eid17eid16 xx-x x-xx 42, 230 txb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 42, 230 txb1con mode 0 ? txabt txlarb txerr txreq ? txpri1 txpri0 -000 0-00 42, 230 txb1con mode 1, 2 txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 42, 230 txb2d7 txb2d77 txb2d76 txb2d75 txb2d74 txb2d73 txb2d72 txb2d71 txb2d70 xxxx xxxx 42, 230 txb2d6 txb2d67 txb2d66 txb2d65 txb2d64 txb2d63 txb2d62 txb2d61 txb2d60 xxxx xxxx 42, 230 txb2d5 txb2d57 txb2d56 txb2d55 txb2d54 txb2d53 txb2d52 txb2d51 txb2d50 xxxx xxxx 42, 230 txb2d4 txb2d47 txb2d46 txb2d45 txb2d44 txb2d43 txb2d42 txb2d41 txb2d40 xxxx xxxx 42, 230 txb2d3 txb2d37 txb2d36 txb2d35 txb2d34 txb2d33 txb2d32 txb2d31 txb2d30 xxxx xxxx 42, 230 txb2d2 txb2d27 txb2d26 txb2d25 txb2d24 txb2d23 txb2d22 txb2d21 txb2d20 xxxx xxxx 42, 230 txb2d1 txb2d17 txb2d16 txb2d15 txb2d14 txb2d13 txb2d12 txb2d11 txb2d10 xxxx xxxx 42, 230 txb2d0 txb2d07 txb2d06 txb2d05 txb2d04 txb2d03 txb2d02 txb2d01 txb2d00 xxxx xxxx 42, 230 txb2dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 42, 230 txb2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 42, 230 txb2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 42, 230 txb2sidl sid2 sid1 sid0 ?exide ?eid17eid16 xxx- x-xx 42, 230 txb2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 42, 230 txb2con mode 0 ? txabt txlarb txerr txreq ? txpri1 txpri0 -000 0-00 42, 230 txb2con mode 1, 2 txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 42, 230 rxm1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 42, 230 rxm1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxm1sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x 0-xx 43, 230 rxm1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxm0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxm0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxm0sidl sid2 sid1 sid0 ?exidm ?eid17eid16 xx-x 0-xx 43, 230 rxm0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf15eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 73 pic18f6585/8585/6680/8680 rxf15eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf15sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 47, 230 rxf15sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 47, 230 rxf14eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf14eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf14sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 47, 230 rxf14sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 47, 230 rxf13eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf13eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf13sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 47, 230 rxf13sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 47, 230 rxf12eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf12eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf12sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 47, 230 rxf12sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 47, 230 rxf11eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf11eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf11sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 47, 230 rxf11sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 47, 230 rxf10eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf10eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 47, 230 rxf10sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 48, 230 rxf10sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 48, 230 rxf9eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 47, 230 rxf9eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 48, 230 rxf9sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 48, 230 rxf9sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 48, 230 rxf8eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 48, 230 rxf8eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 48, 230 rxf8sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 48, 230 rxf8sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 48, 230 rxf7eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 48, 230 rxf7eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 48, 230 rxf7sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 48, 230 rxf7sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 48, 230 rxf6eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 48, 230 rxf6eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 48, 230 rxf6sidl (7) sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 48, 230 rxf6sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 48, 230 rxf5eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf5eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 74 ? 2004 microchip technology inc. rxf5sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf5sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf4eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf4eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxf4sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf4sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf3eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf3eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxf3sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf3sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxf2sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxf1sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 rxf0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 43, 230 rxf0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 43, 230 rxf0sidl sid2 sid1 sid0 ?exiden ?eid17eid16 xx-x x-xx 43, 230 rxf0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 43, 230 b5d7 (7) b5d77 b5d76 b5d75 b5d74 b5d73 b5d72 b5d71 b5d70 xxxx xxxx 44, 230 b5d6 (7) b5d67 b5d66 b5d65 b5d64 b5d63 b5d62 b5d61 b5d60 xxxx xxxx 44, 230 b5d5 (7) b5d57 b5d56 b5d55 b5d54 b5d53 b5d52 b5d51 b5d50 xxxx xxxx 44, 230 b5d4 (7) b5d47 b5d46 b5d45 b5d44 b5d43 b5d42 b5d41 b5d40 xxxx xxxx 44, 230 b5d3 (7) b5d37 b5d36 b5d35 b5d34 b5d33 b5d32 b5d31 b5d30 xxxx xxxx 44, 230 b5d2 (7) b5d27 b5d26 b5d25 b5d24 b5d23 b5d22 b5d21 b5d20 xxxx xxxx 44, 230 b5d1 (7) b5d17 b5d16 b5d15 b5d14 b5d13 b5d12 b5d11 b5d10 xxxx xxxx 44, 230 b5d0 (7) b5d07 b5d06 b5d05 b5d04 b5d03 b5d02 b5d01 b5d00 xxxx xxxx 44, 230 b5dlc (7) ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 44, 230 b5eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 44, 230 b5eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 44, 230 b5sidl (7) sid2 sid1 sid0 srr exid/ exide (5) ?eid17eid16 xxxx x-xx 44, 230 b5sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 44, 230 b5con (5, 7) rxful/ txbif rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 44, 230 b4d7 (7) b4d77 b4d76 b4d75 b4d74 b4d73 b4d72 b4d71 b4d70 xxxx xxxx 44, 230 b4d6 (7) b4d67 b4d66 b4d65 b4d64 b4d63 b4d62 b4d61 b4d60 xxxx xxxx 44, 230 b4d5 (7) b4d57 b4d56 b4d55 b4d54 b4d53 b4d52 b4d51 b4d50 xxxx xxxx 44, 230 b4d4 (7) b4d47 b4d46 b4d45 b4d44 b4d43 b4d42 b4d41 b4d40 xxxx xxxx 44, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 75 pic18f6585/8585/6680/8680 b4d3 (7) b4d37 b4d36 b4d35 b4d34 b4d33 b4d32 b4d31 b4d30 xxxx xxxx 44, 230 b4d2 (7) b4d27 b4d26 b4d25 b4d24 b4d23 b4d22 b4d21 b4d20 xxxx xxxx 44, 230 b4d1 (7) b4d17 b4d16 b4d15 b4d14 b4d13 b4d12 b4d11 b4d10 xxxx xxxx 44, 230 b4d0 (7) b4d07 b4d06 b4d05 b4d04 b4d03 b4d02 b4d01 b4d00 xxxx xxxx 44, 230 b4dlc (7) ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 44, 230 b4eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 44, 230 b4eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 44, 230 b4sidl (7) sid2 sid1 sid0 srr exid/ exide (5) ?eid17eid16 xxxx x-xx 44, 230 b4sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 44, 230 b4con (5, 7) rxful/ txb3if rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 44, 230 b3d7 (7) b3d77 b3d76 b3d75 b3d74 b3d73 b3d72 b3d71 b3d70 xxxx xxxx 44, 230 b3d6 (7) b3d67 b3d66 b3d65 b3d64 b3d63 b3d62 b3d61 b3d60 xxxx xxxx 44, 230 b3d5 (7) b3d57 b3d56 b3d55 b3d54 b3d53 b3d52 b3d51 b3d50 xxxx xxxx 44, 230 b3d4 (7) b3d47 b3d46 b3d45 b3d44 b3d43 b3d42 b3d41 b3d40 xxxx xxxx 45, 230 b3d3 (7) b3d37 b3d36 b3d35 b3d34 b3d33 b3d32 b3d31 b3d30 xxxx xxxx 45, 230 b3d2 (7) b3d27 b3d26 b3d25 b3d24 b3d23 b3d22 b3d21 b3d20 xxxx xxxx 45, 230 b3d1 (7) b3d17 b3d16 b3d15 b3d14 b3d13 b3d12 b3d11 b3d10 xxxx xxxx 45, 230 b3d0 (7) b3d07 b3d06 b3d05 b3d04 b3d03 b3d02 b3d01 b3d00 xxxx xxxx 45, 230 b3dlc (7) ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 45, 230 b3eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 45, 230 b3eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 45, 230 b3sidl (7) sid2 sid1 sid0 srr exid/ exide (5) ?eid17eid16 xxxx x-xx 45, 230 b3sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 45, 230 b3con (5, 7) rxful/ txbif rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 45, 230 b2d7 (7) b2d77 b2d76 b2d75 b2d74 b2d73 b2d72 b2d71 b2d70 xxxx xxxx 45, 230 b2d6 (7) b2d67 b2d66 b2d65 b2d64 b2d63 b2d62 b2d61 b2d60 xxxx xxxx 45, 230 b2d5 (7) b2d57 b2d56 b2d55 b2d54 b2d53 b2d52 b2d51 b2d50 xxxx xxxx 45, 230 b2d4 (7) b2d47 b2d46 b2d45 b2d44 b2d43 b2d42 b2d41 b2d40 xxxx xxxx 45, 230 b2d3 (7) b2d37 b2d36 b2d35 b2d34 b2d33 b2d32 b2d31 b2d30 xxxx xxxx 45, 230 b2d2 (7) b2d27 b2d26 b2d25 b2d24 b2d23 b2d22 b2d21 b2d20 xxxx xxxx 45, 230 b2d1 (7) b2d17 b2d16 b2d15 b2d14 b2d13 b2d12 b2d11 b2d10 xxxx xxxx 45, 230 b2d0 (7) b2d07 b2d06 b2d05 b2d04 b2d03 b2d02 b2d01 b2d00 xxxx xxxx 45, 230 b2dlc (7) ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 45, 230 b2eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 45, 230 b2eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 45, 230 b2sidl (7) sid2 sid1 sid0 srr exid/ exide (5) ?eid17eid16 xxxx x-xx 45, 230 b2sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 45, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 76 ? 2004 microchip technology inc. b2con (5, 7) rxful/ txbif rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 45, 230 b1d7 (7) b1d77 b1d76 b1d75 b1d74 b1d73 b1d72 b1d71 b1d70 xxxx xxxx 45, 230 b1d6 (7) b1d67 b1d66 b1d65 b1d64 b1d63 b1d62 b1d61 b1d60 xxxx xxxx 45, 230 b1d5 (7) b1d57 b1d56 b1d55 b1d54 b1d53 b1d52 b1d51 b1d50 xxxx xxxx 45, 230 b1d4 (7) b1d47 b1d46 b1d45 b1d44 b1d43 b1d42 b1d41 b1d40 xxxx xxxx 45, 230 b1d3 (7) b1d37 b1d36 b1d35 b1d34 b1d33 b1d32 b1d31 b1d30 xxxx xxxx 45, 230 b1d2 (7) b1d27 b1d26 b1d25 b1d24 b1d23 b1d22 b1d21 b1d20 xxxx xxxx 45, 230 b1d1 (7) b1d17 b1d16 b1d15 b1d14 b1d13 b1d12 b1d11 b1d10 xxxx xxxx 46, 230 b1d0 (7) b1d07 b1d06 b1d05 b1d04 b1d03 b1d02 b1d01 b1d00 xxxx xxxx 46, 230 b1dlc (7) ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 46, 230 b1eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 46, 230 b1eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 46, 230 b1sidl (7) sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 46, 230 b1sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 46, 230 b1con (5, 7) rxful/ txbif rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 46, 230 b0d7 (7) b0d77 b0d76 b0d75 b0d74 b0d73 b0d72 b0d71 b0d70 xxxx xxxx 46, 230 b0d6 (7) b0d67 b0d66 b0d65 b0d64 b0d63 b0d62 b0d61 b0d60 xxxx xxxx 46, 230 b0d5 (7) b0d57 b0d56 b0d55 b0d54 b0d53 b0d52 b0d51 b0d50 xxxx xxxx 46, 230 b0d4 (7) b0d47 b0d46 b0d45 b0d44 b0d43 b0d42 b0d41 b0d40 xxxx xxxx 46, 230 b0d3 (7) b0d37 b0d36 b0d35 b0d34 b0d33 b0d32 b0d31 b0d30 xxxx xxxx 46, 230 b0d2 (7) b0d27 b0d26 b0d25 b0d24 b0d23 b0d22 b0d21 b0d20 xxxx xxxx 46, 230 b0d1 (7) b0d17 b0d16 b0d15 b0d14 b0d13 b0d12 b0d11 b0d10 xxxx xxxx 46, 230 b0d0 (7) b0d07 b0d06 b0d05 b0d04 b0d03 b0d02 b0d01 b0d00 xxxx xxxx 46, 230 b0dlc (7) ? rtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 46, 230 b0eidl (7) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 46, 230 b0eidh (7) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 46, 230 b0sidl (7) sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 46, 230 b0sidh (7) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 46, 230 b0con (5, 7) rxful/ txbif rxm1/ txabt rtrro/ txlarb filhit4/ txerr filhit3/ txreq filhit2/ rtren filhit1/ txpri1 filhit0/ txpri0 0000 0000 46, 230 txbie (7) ? ? ? txb2ie txb1ie txb0ie ? ? ---0 00-- 46, 230 bie0 (7) b5ie b4ie b3ie b2ie b1ie b0ie rxb1ie rxb0ie 0000 0000 46, 230 bsel0 (7) b5txen b4txen b3txen b2txen b1txen b0txen ? ? 0000 00-- 46, 230 msel3 (7) fil15_1 fil15_0 fil14_1 fil14_0 fil13_1 fil13_0 fil12_1 fil12_0 0000 0000 46, 230 msel2 (7) fil11_1 fil11_0 fil10_1 fil10_0 fil9_1 fil9_0 fil8_1 fil8_0 0000 0000 46, 230 msel1 (7) fil7_1 fil7_0 fil6_1 fil6_0 fil5_1 fil5_0 fil4_1 fil4_0 0000 0101 46, 230 msel0 (7) fil3_1 fil3_0 fil2_1 fil2_0 fil1_1 fil1_0 fil0_1 fil0_0 0101 0000 46, 230 sdflc (7) ? ? ? dflc4 dflc3 dflc2 dflc1 dflc0 ---0 0000 46, 230 rxfcon1 (7) rxf15en rxf14en rxf13en rxf12en rxf11en rxf10en rxf9en rxf8en 0000 0000 46, 230 rxfcon0 (7) rxf7en rxf6en rxf5en rxf4en rxf3en rxf2en rxf1en rxf0en 0011 1111 47, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
? 2004 microchip technology inc. ds30491c-page 77 pic18f6585/8585/6680/8680 rxfbcon7 (7) f15bp_3 f15bp_2 f15bp_1 f15bp_0 f14bp_3 f14bp_2 f14bp_1 f14bp_01 0000 0000 47, 230 rxfbcon6 (7) f13bp_3 f13bp_2 f13bp_1 f13bp_0 f12bp_3 f12bp_2 f12bp_1 f12bp_01 0000 0000 47, 230 rxfbcon5 (7) f11bp_3 f11bp_2 f11bp_1 f11bp_0 f10bp_3 f10bp_2 f10bp_1 f10bp_01 0000 0000 47, 230 rxfbcon4 (7) f9bp_3 f9bp_2 f9bp_1 f9bp_0 f8bp_3 f8bp_2 f8bp_1 f8bp_01 0000 0000 47, 230 rxfbcon3 (7) f7bp_3 f7bp_2 f7bp_1 f7bp_0 f6bp_3 f6bp_2 f6bp_1 f6bp_01 0000 0000 47, 230 rxfbcon2 (7) f5bp_3 f5bp_2 f5bp_1 f5bp_0 f4bp_3 f4bp_2 f4bp_1 f4bp_01 0000 0000 47, 230 rxfbcon1 (7) f3bp_3 f3bp_2 f3bp_1 f3bp_0 f2bp_3 f2bp_2 f2bp_1 f2bp_01 0000 0000 47, 230 rxfbcon0 (7) f1bp_3 f1bp_2 f1bp_1 f1bp_0 f0bp_3 f0bp_2 f0bp_1 f0bp_01 0000 0000 47, 230 table 4-3: register file summary (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, ? = unimplemented, q = value depends on condition note 1: ra6 and associated bits are configured as port pins in rcio and ecio oscillator mode only and read ? 0 ? in all other oscillator modes. 2: bit 21 of the tblptru allows access to the device configuration bits. 3: these registers are unused on pic18f6x80 devices; always maintain these clear. 4: these bits have multiple functions depending on the can module mode selection. 5: meaning of this register depends on whether this buffer is configured as transmit or receive. 6: rg5 is available as an input when mclr is disabled. 7: this register reads all ? 0 ?s until the ecan module is set up in mode 1 or mode 2.
pic18f6585/8585/6680/8680 ds30491c-page 78 ? 2004 microchip technology inc. 4.10 access bank the access bank is an architectural enhancement which is very useful for c compiler code optimization. the techniques used by the c compiler may also be useful for programs written in assembly. this data memory region can be used for:  intermediate computational values  local variables of subroutines  faster context saving/switching of variables  common variables  faster evaluation/control of sfrs (no banking) the access bank is comprised of the upper 160 bytes in bank 15 (sfrs) and the lower 96 bytes in bank 0. these two sections will be referred to as access ram high and access ram low, respectively. figure 4-7 indicates the access ram areas. a bit in the instruction word specifies if the operation is to occur in the bank specified by the bsr register or in the access bank. this bit is denoted by the ?a? bit (for access bit). when forced in the access bank (a = 0 ), the last address in access ram low is followed by the first address in access ram high. access ram high maps the special function registers so that these registers can be accessed without any software overhead. this is useful for testing status flags and modifying control bits. 4.11 bank select register (bsr) the need for a large general purpose memory space dictates a ram banking scheme. the data memory is partitioned into sixteen banks. when using direct addressing, the bsr should be configured for the desired bank. bsr<3:0> holds the upper 4 bits of the 12-bit ram address. the bsr<7:4> bits will always read ? 0 ?s and writes will have no effect. a movlb instruction has been provided in the instruction set to assist in selecting banks. if the currently selected bank is not implemented, any read will return all ? 0 ?s and all writes are ignored. the status register bits will be set/cleared as appropriate for the instruction performed. each bank extends up to 0ffh (256 bytes). all data memory is implemented as static ram. a movff instruction ignores the bsr since the 12-bit addresses are embedded into the instruction word. section 4.12 ?indirect addressing, indf and fsr registers? provides a description of indirect address- ing which allows linear addressing of the entire ram space. figure 4-8: direct addressing note 1: for register file map detail, see table 4-2. 2: the access bit of the instruction can be used to forc e an override of the selected bank (bsr<3:0>) to the registers of the access bank. 3: the movff instruction embeds the entire 12-bit address in the instruction. data memory (1) direct addressing bank select (2) location select (3) bsr<3:0> 7 0 from opcode (3) 00h 01h 0eh 0fh bank 0 bank 1 bank 14 bank 15 1ffh 100h 0ffh 000h effh e00h fffh f00h
? 2004 microchip technology inc. ds30491c-page 79 pic18f6585/8585/6680/8680 4.12 indirect addressing, indf and fsr registers indirect addressing is a mode of addressing data mem- ory where the data memory address in the instruction is not fixed. an fsr register is used as a pointer to the data memory location that is to be read or written. since this pointer is in ram, the contents can be modified by the program. this can be useful for data tables in the data memory and for software stacks. figure 4-9 shows the operation of indirect addressing. this shows the moving of the value to the data memory address specified by the value of the fsr register. indirect addressing is possible by using one of the indf registers. any instruction using the indf register actually accesses the register pointed to by the file select register, fsr. reading the indf register itself, indirectly (fsr = 0 ), will read 00h. writing to the indf register indirectly, results in a no operation. the fsr register contains a 12-bit address which is shown in figure 4-10. the indfn register is not a physical register. address- ing indfn actually addresses the register whose address is contained in the fsrn register (fsrn is a pointer). this is indirect addressing. example 4-4 shows a simple use of indirect addressing to clear the ram in bank 1 (locations 100h-1ffh) in a minimum number of instructions. example 4-4: how to clear ram (bank 1) using indirect addressing there are three indirect addressing registers. to address the entire data memory space (4096 bytes), these registers are 12-bits wide. to store the 12 bits of addressing information, two 8-bit registers are required. these indirect addressing registers are: 1. fsr0: composed of fsr0h:fsr0l 2. fsr1: composed of fsr1h:fsr1l 3. fsr2: composed of fsr2h:fsr2l in addition, there are registers indf0, indf1 and indf2 which are not physically implemented. reading or writing to these registers activates indirect address- ing with the value in the corresponding fsr register being the address of the data. if an instruction writes a value to indf0, the value will be written to the address pointed to by fsr0h:fsr0l. a read from indf1 reads the data from the address pointed to by fsr1h:fsr1l. indfn can be used in code anywhere an operand can be used. if indf0, indf1, or indf2 are read indirectly via an fsr, all ? 0 ?s are read (zero bit is set). similarly, if indf0, indf1, or indf2 are written to indirectly, the operation will be equivalent to a nop instruction and the status bits are not affected. 4.12.1 indirect addressing operation each fsr register has an indf register associated with it plus four additional register addresses. performing an operation on one of these five registers determines how the fsr will be modified during indirect addressing. when data access is done to one of the five indfn locations, the address selected will configure the fsrn register to:  do nothing to fsrn after an indirect access (no change) ? indfn.  auto-decrement fsrn after an indirect access (post-decrement) ? postdecn.  auto-increment fsrn after an indirect access (post-increment) ? postincn.  auto-increment fsrn before an indirect access (pre-increment) ? preincn.  use the value in the wreg register as an offset to fsrn. do not modify the value of the wreg or the fsrn register after an indirect access (no change) ? pluswn. when using the auto-increment or auto-decrement fea- tures, the effect on the fsr is not reflected in the status register. for example, if the indirect address causes the fsr to equal ? 0 ?, the z bit will not be set. incrementing or decrementing an fsr affects all 12 bits. that is, when fsrnl overflows from an increment, fsrnh will be incremented automatically. adding these features allows the fsrn to be used as a stack pointer in addition to its uses for table operations in data memory. each fsr has an address associated with it that performs an indexed indirect access. when a data access to this indfn location (pluswn) occurs, the fsrn is configured to add the signed value in the wreg register and the value in fsr to form the address before an indirect access. the fsr value is not changed. if an fsr register contains a value that points to one of the indfn, an indirect read will read 00h (zero bit is set), while an indirect write will be equivalent to a nop (status bits are not affected). lfsr fsr0, 100h ; next clrf postinc0 ; clear indf ; register and ; inc pointer btfss fsr0h, 1 ; all done with ; bank1? bra next ; no, clear next continue ; yes, continue
pic18f6585/8585/6680/8680 ds30491c-page 80 ? 2004 microchip technology inc. if an indirect addressing operation is done where the target address is an fsrnh or fsrnl register, the write operation will dominate over the pre- or post-increment/decrement functions. figure 4-9: indirect addressing operation figure 4-10: indirect addressing opcode address file address = access of an indirect addressing register fsr instruction executed instruction fetched ram opcode file 12 12 12 bsr<3:0> 8 4 0h 0fffh note 1: for register file map detail, see table 4-2. data memory (1) indirect addressing fsr register 11 0 0fffh 0000h location select
? 2004 microchip technology inc. ds30491c-page 81 pic18f6585/8585/6680/8680 4.13 status register the status register, shown in register 4-3, contains the arithmetic status of the alu. the status register can be the destination for any instruction as with any other reg- ister. if the status register is the destination for an instruction that affects the z, dc, c, ov or n bits, then the write to these five bits is disabled. these bits are set or cleared according to the device logic. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as 000u u1uu (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf, movff and movwf instructions are used to alter the status register because these instructions do not affect the z, c, dc, ov or n bits from the status register. for other instructions not affecting any status bits, see table 25-2. register 4-3: status register note: the c and dc bits operate as a borrow and digit borrow bit respectively, in subtraction. u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?novzdcc bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the 7-bit magnitude which causes the sign bit (bit 7) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit for addwf, addlw, sublw , and subwf instructions: 1 = a carry-out from the 4th low order bit of the result occurred 0 = no carry-out from the 4th low order bit of the result note: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with either the bit 4 or bit 3 of the source register. bit 0 c: carry/borrow bit for addwf, addlw, sublw , and subwf instructions: 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 82 ? 2004 microchip technology inc. 4.14 rcon register the reset control (rcon) register contains flag bits that allow differentiation between the sources of a device reset. these flags include the to , pd , por , bor and ri bits. this register is readable and writable. register 4-4: rcon register note 1: it is recommended that the por bit be set after a power-on reset has been detected so that subsequent power-on resets may be detected. 2: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assum- ing that por was set to ? 1 ? by software immediately after por). r/w-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-0 r/w-0 ipen ? ?ri to pd por bor bit 7 bit 0 bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6-5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed 0 = the reset instruction was executed causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = after power-up, clrwdt instruction, or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 1 por : power-on reset status bit 1 = a power-on reset has not occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 83 pic18f6585/8585/6680/8680 5.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on one byte at a time. a write to program memory is executed on blocks of 8 bytes at a time. program memory is erased in blocks of 64 bytes at a time. a bulk erase operation cannot be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 5.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram:  table read ( tblrd )  table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8-bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and places it into the data ram space. figure 5-1 shows the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 5.5 ?writing to flash program memory? . figure 5-2 shows the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word aligned. figure 5-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer points to a byte in program memory. program memory (tblptr)
pic18f6585/8585/6680/8680 ds30491c-page 84 ? 2004 microchip technology inc. figure 5-2: table write operation 5.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. these include the:  eecon1 register  eecon2 register  tablat register  tblptr registers 5.2.1 eecon1 and eecon2 registers eecon1 is the control register for memory accesses. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the memory write and erase sequences. control bit eepgd determines if the access will be a program or data eeprom memory access. when clear, any subsequent operations will operate on the data eeprom memory. when set, any subsequent operations will operate on the program memory. control bit cfgs determines if the access will be to the configuration/calibration registers or to program memory/data eeprom memory. when set, subse- quent operations will operate on configuration registers regardless of eepgd (see section 24.0 ?special features of the cpu? ). when clear, memory selection access is determined by eepgd. the free bit, when set, will allow a program memory erase operation. when the free bit is set, the erase operation is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time-out reset during normal opera- tion. in these situations, the user can check the wrerr bit and rewrite the location. it is necessary to reload the data and address registers (eedata and eeadr) due to reset values of zero. the wr control bit initiates write operations. the bit cannot be cleared, only set in software; it is cleared in hardware at the completion of the write operation. the inability to clear the wr bit in software prevents the accidental or premature termination of a write operation. table pointer (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt * note 1: table pointer actually points to one of eight holdi ng registers, the address of which is determined by tblptrl<2:0>. the process for physically writing data to the program memory array is discussed in section 5.5 ?writing to flash program memory? . holding registers program memory note: interrupt flag bit, eeif in the pir2 register, is set when the write is complete. it must be cleared in software.
? 2004 microchip technology inc. ds30491c-page 85 pic18f6585/8585/6680/8680 register 5-1: eecon1 register (address fa6h) r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr wren wr rd bit 7 bit 0 bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write only bit 3 wrerr: flash program/data eeprom error flag bit 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation) 0 = the write operation completed note: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition. bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read. (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 .) 0 = does not initiate an eeprom read legend: r = readable bit u = unimplemented bit, read as ?0? w = writable bit s = settable bit - n = value after erase ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 86 ? 2004 microchip technology inc. 5.2.2 tablat ? table latch register the table latch (tablat) is an 8-bit register mapped into the sfr space. the table latch is used to hold 8- bit data during data transfers between program memory and data ram. 5.2.3 tblptr ? table pointer register the table pointer (tblptr) addresses a byte within the program memory. the tblptr is comprised of three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three regis- ters join to form a 22-bit wide pointer. the low-order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22nd bit allows access to the device id, the user id and the configuration bits. the table pointer, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways based on the table opera- tion. these operations are shown in table 5-1. these operations on the tblptr only affect the low-order 21 bits. 5.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the table pointer determine which byte is read from program memory into tablat. when a tblwt is executed, the three lsbs of the table pointer (tblptr<2:0>) determine which of the eight program memory holding registers is written to. when the timed write to program memory (long write) begins, the 19 msbs of the table pointer (tblptr<21:3>) will determine which program memory block of 8 bytes is written to. for more detail, see section 5.5 ?writing to flash program memory? . when an erase of program memory is executed, the 16 msbs of the table pointer (tblptr<21:6>) point to the 64-byte block that will be erased. the least significant bits (tblptr<5:0>) are ignored. figure 5-3 describes the relevant boundaries of tblptr based on flash program memory operations. table 5-1: table pointer operations with tblrd and tblwt instructions figure 5-3: table pointer boundaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 erase ? tblptr<20:6> write ? tblptr<21:3> read ? tblptr<21:0> tblptrl tblptrh tblptru
? 2004 microchip technology inc. ds30491c-page 87 pic18f6585/8585/6680/8680 5.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the least significant bit of the address selects between the high and low bytes of the word. figure 5-4 shows the interface between the internal program memory and the tablat. figure 5-4: reads from flash program memory example 5-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tablat tblptr = xxxxx1 fetch instruction register (ir) read register tblptr = xxxxx0 movlw upper(code_addr) ; load tblptr with the base movwf tblptru ; address of the word movlw high(code_addr) movwf tblptrh movlw low(code_addr_low) movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf lsb tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf msb
pic18f6585/8585/6680/8680 ds30491c-page 88 ? 2004 microchip technology inc. 5.4 erasing flash program memory the minimum erase block is 32 words or 64 bytes. only through the use of an external programmer or through icsp control can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 64 bytes of program memory is erased. the most significant 16 bits of the tblptr<21:6> point to the block being erased. tblptr<5:0> are ignored. the eecon1 register commands the erase operation. the eepgd bit must be set to point to the flash program memory. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 5.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load table pointer with address of row being erased. 2. set the eecon1 register for the erase operation:  set eepgd bit to point to program memory;  clear the cfgs bit to access program memory;  set wren bit to enable writes;  set free bit to enable the erase. 3. disable interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit. this will begin the row erase cycle. 7. the cpu will stall for duration of the erase (about 2 ms using internal timer). 8. execute a nop . 9. re-enable interrupts. example 5-2: erasing a flash program memory row movlw upper(code_addr) ; load tblptr with the base movwf tblptru ; address of the memory block movlw high(code_addr) movwf tblptrh movlw low(code_addr) movwf tblptrl erase_row bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts movlw 55h movwf eecon2 ; write 55h required movlw 0aah sequence movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) nop bsf intcon, gie ; re-enable interrupts
? 2004 microchip technology inc. ds30491c-page 89 pic18f6585/8585/6680/8680 5.5 writing to flash program memory the minimum programming block is 4 words or 8 bytes. word or byte programming is not supported. table writes are used internally to load the holding registers needed to program the flash memory. there are eight holding registers used by the table writes for programming. since the table latch (tablat) is only a single byte, the tblwt instruction has to be executed 8 times for each programming operation. all of the table write operations will essentially be short writes because only the holding registers are written. at the end of updating eight registers, the eecon1 register must be written to, to start the programming operation with a long write. the long write is necessary for programming the inter- nal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. the eeprom on-chip timer controls the write time. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device for byte or word operations. figure 5-5: table writes to flash program memory holding register tablat holding register tblptr = xxxxx7 holding register tblptr = xxxxx1 holding register tblptr = xxxxx0 8 8 8 8 write register tblptr = xxxxx2 program memory
pic18f6585/8585/6680/8680 ds30491c-page 90 ? 2004 microchip technology inc. 5.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read 64 bytes into ram. 2. update data values in ram as necessary. 3. load table pointer with address being erased. 4. do the row erase procedure. 5. load table pointer with address of first byte being written. 6. write the first 8 bytes into the holding registers with auto-increment. 7. set the eecon1 register for the write operation:  set eepgd bit to point to program memory;  clear the cfgs bit to access program memory;  set wren to enable byte writes. 8. disable interrupts. 9. write 55h to eecon2. 10. write 0aah to eecon2. 11. set the wr bit. this will begin the write cycle. 12. the cpu will stall for duration of the write (about 5 ms using internal timer). 13. execute a nop . 14. re-enable interrupts. 15. repeat steps 6-14 seven times to write 64 bytes. 16. verify the memory (table read). this procedure will require about 40 ms to update one row of 64 bytes of memory. an example of the required code is given in example 5-3. example 5-3: writing to flash program memory note: before setting the wr bit, the table pointer address needs to be within the intended address range of the eight bytes in the holding register. movlw d?64 ; number of bytes in erase block movwf counter movlw high(buffer_addr) ; point to buffer movwf fsr0h movlw low(buffer_addr) movwf fsr0l movlw upper(code_addr) ; load tblptr with the base movwf tblptru ; address of the memory block movlw high(code_addr) movwf tblptrh movlw low(code_addr) movwf tblptrl read_block tblrd*+ ; read into tablat, and inc movf tablat, w ; get data movwf postinc0 ; store data decfsz counter ; done? bra read_block ; repeat modify_word movlw high(data_addr) ; point to buffer movwf fsr0h movlw low(data_addr) movwf fsr0l movlw low(new_data) ; update buffer word movwf postinc0 movlw high(new_data) movwf indf0
? 2004 microchip technology inc. ds30491c-page 91 pic18f6585/8585/6680/8680 example 5-3: writing to flash program memory (continued) erase_block movlw upper(code_addr) ; load tblptr with the base movwf tblptru ; address of the memory block movlw high(code_addr) movwf tblptrh movlw low(code_addr) movwf tblptrl bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts movlw 55h movwf eecon2 ; write 55h required movlw 0aah sequence movwf eecon2 ; write aah bsf eecon1, wr ; start erase (cpu stall) nop bsf intcon, gie ; re-enable interrupts tblrd*- ; dummy read decrement write_buffer_back movlw 8 ; number of write buffer groups of 8 bytes movwf counter_hi movlw high(buffer_addr) ; point to buffer movwf fsr0h movlw low(buffer_addr) movwf fsr0l program_loop movlw 8 ; number of bytes in holding register movwf counter write_word_to_hregs movfw postinc0, w ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_word_to_hregs program_memory bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h movwf eecon2 ; write 55h required movlw 0aah sequence movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) nop bsf intcon, gie ; re-enable interrupts decfsz counter_hi ; loop until done bra program_loop bcf eecon1, wren ; disable write to memory
pic18f6585/8585/6680/8680 ds30491c-page 92 ? 2004 microchip technology inc. 5.5.2 write verify depending on the application, good programming practice may dictate that the value written to the mem- ory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 5.5.3 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and repro- grammed if needed. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation. in these situations, users can check the wrerr bit and rewrite the location. 5.5.4 protection against spurious writes to protect against spurious writes to flash program memory, the write initiate sequence must also be followed. see section 24.0 ?special features of the cpu? for more detail. 5.6 flash program operation during code protection see section 24.0 ?special features of the cpu? for details on code protection of flash program memory. table 5-2: registers associated with program flash memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) --00 0000 --00 0000 tbpltrh program memory table pointer high byte (tblptr<15:8>) 0000 0000 0000 0000 tblptrl program memory table pointer high byte (tblptr<7:0>) 0000 0000 0000 0000 tablat program memory table latch 0000 0000 0000 0000 intcon gie/gieh peie/giel tmr0ie inte rbie tmr0if intf rbif 0000 0000 0000 0000 eecon2 eeprom control register 2 (not a physical register) ? ? eecon1 eepgd cfgs ? free wrerr wren wr rd xx-0 x000 uu-0 u000 ipr2 ? cmip ?eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 -1-1 1111 pir2 ? cmif ?eeif bclif lvdif tmr3if ccp2if -0-0 0000 -0-0 0000 pie2 ? cmie ?eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 -0-0 0000 legend: x = unknown, u = unchanged, r = reserved, ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access.
? 2004 microchip technology inc. ds30491c-page 93 pic18f6585/8585/6680/8680 6.0 external memory interface the external memory interface is a feature of the pic18f8x8x devices that allows the controller to access external memory devices (such as flash, eprom, sram, etc.) as program memory. the physical implementation of the interface uses 27 pins. these pins are reserved for external address/ data bus functions; they are multiplexed with i/o port pins on four ports. three i/o ports are multiplexed with the address/data bus, while the fourth port is multi- plexed with the bus control signals. the i/o port func- tions are enabled when the ebdis bit in the memcon register is set (see register 6-1). a list of the multiplexed pins and their functions is provided in table 6-1. as implemented in the pic18f8x8x devices, the interface operates in a similar manner to the external memory interface introduced on pic18c601/801 microcontrollers. the most notable difference is that the interface on pic18f8x8x devices only operates in 16-bit modes. the 8-bit mode is not supported. for a more complete discussion of the operating modes that use the external memory interface, refer to section 4.1.1 ?pic18f8x8x program memory modes? . 6.1 program memory modes and the external memory interface as previously noted, pic18f8x8x controllers are capable of operating in any one of four program mem- ory modes using combinations of on-chip and external program memory. the functions of the multiplexed port pins depend on the program memory mode selected as well as the setting of the ebdis bit. in microprocessor mode , the external bus is always active and the port pins have only the external bus function. in microcontroller mode, the bus is not active and the pins have their port functions only. writes to the memcom register are not permitted. in microprocessor with boot block or extended microcontroller mode, the external program memory bus shares i/o port functions on the pins. when the device is fetching or doing table read/table write operations on the external program memory space, the pins will have the external bus function. if the device is fetching and accessing internal program memory locations only, the ebdis control bit will change the pins from external memory to i/o port functions. when ebdis = 0 , the pins function as the external bus. when ebdis = 1 , the pins function as i/o ports. note: the external memory interface is not implemented on pic18f6x8x (64/68-pin) devices.
pic18f6585/8585/6680/8680 ds30491c-page 94 ? 2004 microchip technology inc. register 6-1: memcon register r/w-0 u-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r/w-0 ebdis (1) ?wait1wait0 ? ?wm1wm0 bit 7 bit 0 bit 7 ebdis : external bus disable bit (1) 1 = external system bus disabled, all external bus drivers are mapped as i/o ports 0 = external system bus enabled and i/o ports are disabled note 1: this bit is ignored when device is accessing external memory either to fetch an instruction or perform tblrd/tblwt . bit 6 unimplemented : read as ? 0 ? bit 5-4 wait<1:0> : table reads and writes bus cycle wait count bits 11 = table reads and writes will wait 0 t cy 10 = table reads and writes will wait 1 t cy 01 = table reads and writes will wait 2 t cy 00 = table reads and writes will wait 3 t cy bit 3-2 unimplemented : read as ? 0 ? bit 1-0 wm<1:0> : tblwt operation with 16-bit bus bits 1x = word write mode: lsb and msb word output, wrh active when msb written 01 = byte select mode: tablat data copied on both ms and ls byte, wrh and (ub or lb ) will activate 00 = byte write mode: tablat data copied on both ms and ls byte, wrh or wrl will activate legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: the memcon register is held in reset in microcontroller mode.
? 2004 microchip technology inc. ds30491c-page 95 pic18f6585/8585/6680/8680 if the device fetches or accesses external memory while ebdis = 1 , the pins will switch to external bus. if the ebdis bit is set by a program executing from exter- nal memory, the action of setting the bit will be delayed until the program branches into the internal memory. at that time, the pins will change from external bus to i/o ports. when the device is executing out of internal memory (with ebdis = 0 ) in microprocessor with boot block mode or extended microcontroller mode, the control sig- nals will be in inactive. they will go to a state where the ad<15:0>, a<19:16> are tri-state; the oe , wrh , wrl , ub and lb signals are ? 1 ?; and ale and ba0 are ? 0 ?. table 6-1: pic18f8x8x external bus ? i/o port functions name port bit function rd0/ad0 portd bit 0 input/output or system bus address bit 0 or data bit 0 rd1/ad1 portd bit 1 input/output or system bus address bit 1 or data bit 1 rd2/ad2 portd bit 2 input/output or system bus address bit 2 or data bit 2 rd3/ad3 portd bit 3 input/output or system bus address bit 3 or data bit 3 rd4/ad4 portd bit 4 input/output or system bus address bit 4 or data bit 4 rd5/ad5 portd bit 5 input/output or system bus address bit 5 or data bit 5 rd6/ad6 portd bit 6 input/output or system bus address bit 6 or data bit 6 rd7/ad7 portd bit 7 input/output or system bus address bit 7 or data bit 7 re0/ad8 porte bit 0 input/output or system bus address bit 8 or data bit 8 re1/ad9 porte bit 1 input/output or system bus address bit 9 or data bit 9 re2/ad10 porte bit 2 input/output or system bus address bit 10 or data bit 10 re3/ad11 porte bit 3 input/output or system bus address bit 11 or data bit 11 re4/ad12 porte bit 4 input/output or system bus address bit 12 or data bit 12 re5/ad13 porte bit 5 input/output or system bus address bit 13 or data bit 13 re6/ad14 porte bit 6 input/output or system bus address bit 14 or data bit 14 re7/ad15 porte bit 7 input/output or system bus address bit 15 or data bit 15 rh0/a16 porth bit 0 input/output or system bus address bit 16 rh1/a17 porth bit 1 input/output or system bus address bit 17 rh2/a18 porth bit 2 input/output or system bus address bit 18 rh3/a19 porth bit 3 input/output or system bus address bit 19 rj0/ale portj bit 0 input/output or system bus address latch enable (ale) control pin rj1/oe portj bit 1 input/output or system bus output enable (oe ) control pin rj2/wrl portj bit 2 input/output or system bus write low (wrl ) control pin rj3/wrh portj bit 3 input/output or system bus write high (wrh ) control pin rj4/ba0 portj bit 4 input/output or system bus byte address bit 0 rj5/ce portj bit 5 input/output or chip enable rj6/lb portj bit 6 input/output or system bus lower byte enable (lb ) control pin rj7/ub portj bit 7 input/output or system bus upper byte enable (ub ) control pin
pic18f6585/8585/6680/8680 ds30491c-page 96 ? 2004 microchip technology inc. 6.2 16-bit mode the external memory interface implemented in pic18f8x8x devices operates only in 16-bit mode. the mode selection is not software configurable but is programmed via the configuration bits. the wm<1:0> bits in the memcon register determine three types of connections in 16-bit mode. they are referred to as:  16-bit byte write  16-bit word write  16-bit byte select these three different configurations allow the designer maximum flexibility in using 8-bit and 16-bit memory devices. for all 16-bit modes, the address latch enable (ale) pin indicates that the address bits (a<15:0>) are avail- able on the external memory interface bus. following the address latch, the output enable signal (oe ) will enable both bytes of program memory at once to form a 16-bit instruction word. in byte select mode, jedec standard flash memories will require ba0 for the byte address line, and one i/o line to select between byte and word mode. the other 16-bit modes do not need ba0. jedec standard static ram memories will use the ub or lb signals for byte selection. 6.2.1 16-bit byte write mode figure 6-1 shows an example of 16-bit byte write mode for pic18f8x8x devices. figure 6-1: 16-bit byte write mode example ad<7:0> a<19:16> ale d<15:8> 373 a d<7:0> a<19:0> a d<7:0> 373 oe wrh oe oe wr (1) wr (1) ce ce note 1: this signal only applies to table writes. see section 5.1 ?table reads and table writes? . wrl d<7:0> (lsb) (msb) pic18f8x8x d<7:0> ad<15:8> address bus data bus control lines ce
? 2004 microchip technology inc. ds30491c-page 97 pic18f6585/8585/6680/8680 6.2.2 16-bit word write mode figure 6-2 shows an example of 16-bit word write mode for pic18f8x8x devices. figure 6-2: 16-bit word write mode example ad<7:0> pic18f8x8x ad<15:8> ale 373 a<20:1> 373 o e w rh a<19:16> a d<15:0> oe wr (1) ce d<15:0> jedec word eprom memory address bus data bus control lines note 1: this signal only applies to table writes. see section 5.1 ?table reads and table writes? . ce
pic18f6585/8585/6680/8680 ds30491c-page 98 ? 2004 microchip technology inc. 6.2.3 16-bit byte select mode figure 6-3 shows an example of 16-bit byte select mode for pic18f8x8x devices. figure 6-3: 16-bit byte select mode example ad<7:0> pic18f8x8x ad<15:8> ale 373 a<20:1> 373 o e w rh a<19:16> w rl ba0 a<20:1> ce a0 jedec word a d<15:0> ce d<15:0> oe wr (1) lb ub sram memory lb ub address bus data bus control lines note 1: this signal only applies to table writes. see section 5.1 ?table reads and table writes? .
? 2004 microchip technology inc. ds30491c-page 99 pic18f6585/8585/6680/8680 6.2.4 16-bit mode timing figure 6-4 shows the 16-bit mode external bus timing for pic18f8x8x devices. figure 6-4: external program me mory bus timing (16-bit mode) q2 q1 q3 q4 q2 q1 q3 q4 q4 q4 q4 q4 ale oe 3aabh wrh wrl ad<15:0> ba0 cf33h opcode fetch movlw 55h from 007556h 9256h 0e55h ? 1 ? ? 1 ? ? 1 ? ? 1 ? table read of 92h from 199e67h 1 t cy wait q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 apparent q actual q a<19:16> ch 0h
pic18f6585/8585/6680/8680 ds30491c-page 100 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 101 pic18f6585/8585/6680/8680 7.0 data eeprom memory the data eeprom is readable and writable during nor- mal operation over the entire v dd range. the data memory is not directly mapped in the register file space. instead, it is indirectly addressed through the special function registers (sfr). there are five sfrs used to read and write the program and data eeprom memory. these registers are:  eecon1  eecon2  eedata  eeadr  eeadrh the eeprom data memory allows byte read and write. when interfacing to the data memory block, eedata holds the 8-bit data for read/write and eeadr holds the address of the eeprom location being accessed. these devices have 1024 bytes of data eeprom with an address range from 0h to 3ffh. the eeprom data memory is rated for high erase/ write cycles. a byte write automatically erases the loca- tion and writes the new data (erase-before-write). the write time is controlled by an on-chip timer. the write time will vary with voltage and temperature as well as from chip to chip. please refer to parameter d122 (electrical characteristics, section 27.0 ?electrical characteristics? ) for exact limits. 7.1 eeadrh:eeadr the address register pair, eeadrh:eeadr, can address up to a maximum of 1024 bytes of data eeprom. 7.2 eecon1 and eecon2 registers eecon1 is the control register for eeprom memory accesses. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the eeprom write sequence. control bits rd and wr initiate read and write opera- tions, respectively. these bits cannot be cleared, only set in software. they are cleared in hardware at the completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental or premature termination of a write operation. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time-out reset during normal opera- tion. in these situations, the user can check the wrerr bit and rewrite the location. it is necessary to reload the data and address registers (eedata and eeadr) due to the reset condition forcing the contents of the registers to zero. note: interrupt flag bit, eeif in the pir2 register, is set when write is complete. it must be cleared in software.
pic18f6585/8585/6680/8680 ds30491c-page 102 ? 2004 microchip technology inc. register 7-1: eecon1 register (address fa6h) r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr wren wr rd bit 7 bit 0 bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data ee or configuration select bit 1 = access configuration or calibration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write only bit 3 wrerr: flash program/data ee error flag bit 1 = a write operation is prematurely terminated (any mclr or any wdt reset during self-timed programming in normal operation) 0 = the write operation completed note: when a wrerr occurs, the eepgd or free bits are not cleared. this allows tracing of the error condition. bit 2 wren: flash program/data ee write enable bit 1 = allows write cycles 0 = inhibits write to the eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read. (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 .) 0 = does not initiate an eeprom read legend: r = readable bit u = unimplemented bit, read as ?0? w = writable bit s = settable bit - n = value after erase ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 103 pic18f6585/8585/6680/8680 7.3 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadr register, clear the eepgd con- trol bit (eecon1<7>), clear the cfgs control bit (eecon1<6>) and then set control bit, rd (eecon1<0>). the data is available for the very next instruction cycle; therefore, the eedata register can be read by the next instruction. eedata will hold this value until another read operation or until it is written to by the user (during a write operation). example 7-1: data eeprom read 7.4 writing to the data eeprom memory to write an eeprom data location, the address must first be written to the eeadrh:eeadr register pair and the data written to the eedata register. then the sequence in example 7-2 must be followed to initiate the write cycle. the write will not initiate if the above sequence is not exactly followed (write 55h to eecon2, write 0aah to eecon2, then set wr bit) for each byte. it is strongly recommended that interrupts be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable writes. this mechanism prevents accidental writes to data eeprom due to unexpected code exe- cution (i.e., runaway programs). the wren bit should be kept clear at all times except when updating the eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, eecon1, eeadrh:eeadr and edata cannot be modified. the wr bit will be inhibited from being set unless the wren bit is set. the wren bit must be set on a pre- vious instruction. both wr and wren cannot be set with the same instruction. at the completion of the write cycle, the wr bit is cleared in hardware and the eeprom write complete interrupt flag bit (eeif) is set. the user may either enable this interrupt or poll this bit. eeif must be cleared by software. example 7-2: data eeprom write movlw data_ee_adr_hi ; movwf eeadrh ; movlw data_ee_addr_low ; movwf eeadr ; data memory address to read bcf eecon1, eepgd ; point to data memory bcf eecon1, cfgs ; access program flash or data eeprom memory bsf eecon1, rd ; eeprom read movf eedata, w ; w = eedata movlw data_ee_addr_hi ; movwf eeadrh ; movlw data_ee_addr_low ; movwf eeadr ; data memory address to read movlw data_ee_data ; movwf eedata ; data memory value to write bcf eecon1, eepgd ; point to data memory bcf eecon1, cfgs ; access program flash or data eeprom memory bsf eecon1, wren ; enable writes bcf intcon, gie ; disable interrupts required movlw 55h ; sequence movwf eecon2 ; write 55h movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write bsf intcon, gie ; enable interrupts . ; user code execution . . bcf eecon1, wren ; disable writes on write complete (eeif set)
pic18f6585/8585/6680/8680 ds30491c-page 104 ? 2004 microchip technology inc. 7.5 write verify depending on the application, good programming practice may dictate that the value written to the mem- ory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 7.6 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built-in. on power-up, the wren bit is cleared. also, the power-up timer (72 ms duration) prevents eeprom write. the write initiate sequence and the wren bit together help prevent an accidental write during brown-out, power glitch, or software malfunction. 7.7 operation during code-protect data eeprom memory has its own code-protect mechanism. external read and write operations are disabled if either of these mechanisms are enabled. the microcontroller itself can both read and write to the internal data eeprom regardless of the state of the code-protect configuration bit. refer to section 24.0 ?special features of the cpu? for additional information. 7.8 using the data eeprom the data eeprom is a high endurance, byte address- able array that has been optimized for the storage of frequently changing information (e.g., program vari- ables or other data that are updated often). frequently changing values will typically be updated more often than specification d124. if this is not the case, an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 7-3. example 7-3: data eeprom refresh routine note: if data eeprom is only used to store con- stants and/or data that changes rarely, an array refresh is likely not required. see specification d124. clrf eeadrh ; clrf eeadr ; start at address 0 bcf eecon1, cfgs ; set for memory bcf eecon1, eepgd ; set for data eeprom bcf intcon, gie ; disable interrupts bsf eecon1, wren ; enable writes loop ; loop to refresh array bsf eecon1, rd ; read current address movlw 55h ; movwf eecon2 ; write 55h movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write btfsc eecon1, wr ; wait for write to complete bra $-2 incfsz eeadr, f ; increment address bra loop ; not zero, do it again incfs2 eeadrh, f ; bra loop ; bcf eecon1, wren ; disable writes bsf intcon, gie ; enable interrupts
? 2004 microchip technology inc. ds30491c-page 105 pic18f6585/8585/6680/8680 table 7-1: registers associated with data eeprom memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets intcon gie/ gieh peie/ giel t0ie inte rbie t0if intf rbif 0000 000x 0000 000u eeadrh ? ? ? ? ? ? ee addr high ---- --00 ---- --00 eeadr eeprom address register 0000 0000 0000 0000 eedata eeprom data register 0000 0000 0000 0000 eecon2 eeprom control register 2 (not a physical register) ? ? eecon1 eepgd cfgs ? free wrerr wren wr rd xx-0 x000 uu-0 u000 ipr2 ?cmip ? eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 ---1 1111 pir2 ?cmif ? eeif bclif lvdif tmr3if ccp2if -0-0 0000 ---0 0000 pie2 ?cmie ? eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 ---0 0000 legend: x = unknown, u = unchanged, r = reserved, ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access.
pic18f6585/8585/6680/8680 ds30491c-page 106 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 107 pic18f6585/8585/6680/8680 8.0 8 x 8 hardware multiplier 8.1 introduction an 8 x 8 hardware multiplier is included in the alu of the pic18f6585/8585/6680/8680 devices. by making the multiply a hardware operation, it completes in a sin- gle instruction cycle. this is an unsigned multiply that gives a 16-bit result. the result is stored in the 16-bit product register pair (prodh:prodl). the multiplier does not affect any flags in the alusta register. making the 8 x 8 multiplier execute in a single cycle gives the following advantages:  higher computational throughput  reduces code size requirements for multiply algorithms the performance increase allows the device to be used in applications previously reserved for digital signal processors. table 8-1 shows a performance comparison between enhanced devices using the single-cycle hardware multiply and performing the same function without the hardware multiply. 8.2 operation example 8-1 shows the sequence to do an 8 x 8 unsigned multiply. only one instruction is required when one argument of the multiply is already loaded in the wreg register. example 8-2 shows the sequence to do an 8 x 8 signed multiply. to account for the sign bits of the arguments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 8-1: 8 x 8 unsigned multiply routine example 8-2: 8 x 8 signed multiply routine table 8-1: performance comparison movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh ; prodh = prodh ; - arg1 movf arg2, w ; btfsc arg1, sb ; test sign bit subwf prodh ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 40 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 6.9 s 27.6 s 69 s hardware multiply 1 1 100 ns 400 ns 1 s 8 x 8 signed without hardware multiply 33 91 9.1 s 36.4 s 91 s hardware multiply 6 6 600 ns 2.4 s6 s 16 x 16 unsigned without hardware multiply 21 242 24.2 s 96.8 s 242 s hardware multiply 24 24 2.4 s9.6 s 24 s 16 x 16 signed without hardware multiply 52 254 25.4 s102.6 s 254 s hardware multiply 36 36 3.6 s 14.4 s 36 s
pic18f6585/8585/6680/8680 ds30491c-page 108 ? 2004 microchip technology inc. example 8-3 shows the sequence to do a 16 x 16 unsigned multiply. equation 8-1 shows the algorithm that is used. the 32-bit result is stored in four registers, res3:res0. equation 8-1: 16 x 16 unsigned multiplication algorithm example 8-3: 16 x 16 unsigned multiply routine example 8-4 shows the sequence to do a 16 x 16 signed multiply. equation 8-2 shows the algorithm used. the 32-bit result is stored in four registers, res3:res0. to account for the sign bits of the argu- ments, each argument pairs? most significant bit (msb) is tested and the appropriate subtractions are done. equation 8-2: 16 x 16 signed multiplication algorithm example 8-4: 16 x 16 signed multiply routine movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1 ; add cross movf prodh, w ; products addwfc res2 ; clrf wreg ; addwfc res3 ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1 ; add cross movf prodh, w ; products addwfc res2 ; clrf wreg ; addwfc res3 ; res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 216) + (arg1h ? arg2l ? 28) + (arg1l ? arg2h ? 28) + (arg1l ? arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1 ; add cross movf prodh, w ; products addwfc res2 ; clrf wreg ; addwfc res3 ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1 ; add cross movf prodh, w ; products addwfc res2 ; clrf wreg ; addwfc res3 ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code : res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 216) + (arg1h ? arg2l ? 28) + (arg1l ? arg2h ? 28) + (arg1l ? arg2l) + (-1 ? arg2h<7> ? arg1h:arg1l ? 216) + (-1 ? arg1h<7> ? arg2h:arg2l ? 216)
? 2004 microchip technology inc. ds30491c-page 109 pic18f6585/8585/6680/8680 9.0 interrupts the pic18f6585/8585/6680/8680 devices have multi- ple interrupt sources and an interrupt priority feature that allows each interrupt source to be assigned a high or a low priority level. the high priority interrupt vector is at 000008h while the low priority interrupt vector is at 000018h. high priority interrupt events will override any low priority interrupts that may be in progress. there are thirteen registers which are used to control interrupt operation. they are:  rcon intcon  intcon2  intcon3  pir1, pir2, pir3  pie1, pie2, pie3  ipr1, ipr2, ipr3 it is recommended that the microchip header files supplied with mplab ? ide be used for the symbolic bit names in these registers. this allows the assembler/ compiler to automatically take care of the placement of these bits within the specified register. each interrupt source (except int0) has three bits to control its operation. the functions of these bits are:  flag bit to indicate that an interrupt event occurred  enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set  priority bit to select high priority or low priority the interrupt priority feature is enabled by setting the ipen bit (rcon<7>). when interrupt priority is enabled, there are two bits which enable interrupts globally. setting the gieh bit (intcon<7>) enables all interrupts that have the priority bit set. setting the giel bit (intcon<6>) enables all interrupts that have the priority bit cleared. when the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 000008h or 000018h depending on the priority level. individual interrupts can be disabled through their corresponding enable bits. when the ipen bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with picmicro ? mid-range devices. in com- patibility mode, the interrupt priority bits for each source have no effect. intcon<6> is the peie bit which enables/disables all peripheral interrupt sources. intcon<7> is the gie bit which enables/disables all interrupt sources. all interrupts branch to address 000008h in compatibility mode. when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. if the ipen bit is cleared, this is the gie bit. if interrupt priority levels are used, this will be either the gieh or giel bit. high priority interrupt sources can interrupt a low priority interrupt. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (000008h or 000018h). once in the interrupt service routine, the source(s) of the interrupt can be deter- mined by polling the interrupt flag bits. the interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. the ?return from interrupt? instruction, retfie , exits the interrupt routine and sets the gie bit (gieh or giel if priority levels are used) which re-enables interrupts. for external interrupt events, such as the int pins or the portb input change interrupt, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one- or two-cycle instructions. individual interrupt flag bits are set regardless of the status of their corresponding enable bit or the gie bit.
pic18f6585/8585/6680/8680 ds30491c-page 110 ? 2004 microchip technology inc. figure 9-1: interrupt logic tmr0ie gieh/gie giel/peie wake-up if in sleep mode interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen tmr0if tmr0ip int1if int1ie int1ip int2if int2ie int2ip rbif rbie rbip int0if int0ie giel/peie interrupt to cpu vector to location ipen ipe 0018h peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit tmr1if tmr1ie tmr1ip xxxxif xxxxie xxxxip additional peripheral interrupts tmr1if tmr1ie tmr1ip high priority interrupt generation low priority interrupt generation xxxxif xxxxie xxxxip additional peripheral interrupts gie/geih
? 2004 microchip technology inc. ds30491c-page 111 pic18f6585/8585/6680/8680 9.1 intcon registers the intcon registers are readable and writable registers which contain various enable, priority and flag bits. register 9-1: intcon register note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif bit 7 bit 0 bit 7 gie/gieh: global interrupt enable bit when ipen (rcon<7>) = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts when ipen (rcon<7>) = 1 : 1 = enables all high priority interrupts 0 = disables all interrupts bit 6 peie/giel: peripheral interrupt enable bit when ipen (rcon<7>) = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen (rcon<7>) = 1 : 1 = enables all low priority peripheral interrupts 0 = disables all low priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 rbie: rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit 1 = at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state note: a mismatch condition will continue to set this bit. reading portb will end the mismatch condition and allow the bit to be cleared. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 112 ? 2004 microchip technology inc. register 9-2: intcon2 register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg0 intedg1 intedg2 i ntedg3 tmr0ip int3ip rbip bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0 : external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1 : external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2 : external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 intedg3 : external interrupt 3 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 2 tmr0ip : tmr0 overflow interrupt priority bit 1 = high priority 0 = low priority bit 1 int3ip: int3 external interrupt priority bit 1 = high priority 0 = low priority bit 0 rbip : rb port change interrupt priority bit 1 = high priority 0 = low priority legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
? 2004 microchip technology inc. ds30491c-page 113 pic18f6585/8585/6680/8680 register 9-3: intcon3 register r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if bit 7 bit 0 bit 7 int2ip: int2 external interrupt priority bit 1 = high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 = high priority 0 = low priority bit 5 int3ie: int3 external interrupt enable bit 1 = enables the int3 external interrupt 0 = disables the int3 external interrupt bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 int3if: int3 external interrupt flag bit 1 = the int3 external interrupt occurred (must be cleared in software) 0 = the int3 external interrupt did not occur bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f6585/8585/6680/8680 ds30491c-page 114 ? 2004 microchip technology inc. 9.2 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt flag registers (pir1, pir2 and pir3). register 9-4: pir1: peripheral interrupt request (flag) register 1 note 1: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). 2: user software should ensure the appropri- ate interrupt flag bits are cleared prior to enabling an interrupt, and after servicing that interrupt. r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 pspif: parallel slave port read/write interrupt flag bit (1) 1 = a read or a write operation has taken place (must be cleared in software) 0 = no read or write has occurred bit 6 adif : a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rcif : usart receive interrupt flag bit 1 = the usart receive buffer, rcreg, is full (cleared when rcreg is read) 0 = the usart receive buffer is empty bit 4 txif : usart transmit interrupt flag bit 1 = the usart transmit buffer, txreg, is empty (cleared when txreg is written) 0 = the usart transmit buffer is full bit 3 sspif : master synchronous serial port interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if : enhanced ccp1 interrupt flag bit capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode. bit 1 tmr2if: tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow note 1: available in microcontroller mode only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 115 pic18f6585/8585/6680/8680 register 9-5: pir2: peripheral interrupt request (flag) register 2 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ?cmif ? eeif bclif lvdif tmr3if ccp2if bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 cmif : comparator interrupt flag bit 1 = the comparator input has changed (must be cleared in software) 0 = the comparator input has not changed bit 5 unimplemented: read as ? 0 ? bit 4 eeif : data eeprom/flash write operation interrupt flag bit 1 = the write operation is complete (must be cleared in software) 0 = the write operation is not complete, or has not been started bit 3 bclif : bus collision interrupt flag bit 1 = a bus collision occurred while the ssp module (configured in i 2 c master mode) was transmitting (must be cleared in software) 0 = no bus collision occurred bit 2 lvdif : low-voltage detect interrupt flag bit 1 = a low-voltage condition occurred (must be cleared in software) 0 = the device voltage is above the low-voltage detect trip point bit 1 tmr3if : tmr3 overflow interrupt flag bit 1 = tmr3 register overflowed (must be cleared in software) 0 = tmr3 register did not overflow bit 0 ccp2if : ccp2 interrupt flag bit capture mode: 1 = a tmr1 or tmr3 register capture occurred (must be cleared in software) 0 = no tmr1 or tmr3 register capture occurred compare mode: 1 = a tmr1 or tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1 or tmr3 register compare match occurred pwm mode: unused in this mode. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 116 ? 2004 microchip technology inc. register 9-6: pir3: peripheral interrupt request (flag) register 3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txb2if/ txbnif txb1if (1) txb0if (1) rxb1if/ rxbnif rxb0if/ fifowmif bit 7 bit 0 bit 7 irxif: can invalid received message interrupt flag bit 1 = an invalid message has occurred on the can bus 0 = no invalid message on can bus bit 6 wakif: can bus activity wake-up interrupt flag bit 1 = activity on can bus has occurred 0 = no activity on can bus bit 5 errif: can bus error interrupt flag bit 1 = an error has occurred in the can module (multiple sources) 0 = no can module errors bit 4 when can is in mode 0: txb2if: can transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message when can is in mode 1 or 2: txbnif: any transmit buffer interrupt flag bit 1 = one or more transmit buffers has completed transmission of a message and may be reloaded (txbie or bie0<7:2> must be non-zero) 0 = no message was transmitted bit 3 txb1if: can transmit buffer 1 interrupt flag bit (1) 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: can transmit buffer 0 interrupt flag bit (1) 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 when can is in mode 0: rxb1if: can receive buffer 1 interrupt flag bit 1 = receive buffer 1 has received a new message 0 = receive buffer 1 has not received a new message when can is in mode 1 or 2: rxbnif: can receive buffer interrupt flag bit 1 = one or more receive buffers has received a new message 0 = no receive buffer has received a new message bit 0 when can is in mode 0: rxb0if: can receive buffer 0 interrupt flag bit (1) 1 = receive buffer 0 has received a new message 0 = receive buffer 0 has not received a new message when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmif: fifo watermark interrupt flag bit 1 = fifo high watermark is reached 0 = fifo high watermark is not reached legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 117 pic18f6585/8585/6680/8680 9.3 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt enable registers (pie1, pie2 and pie3). when the ipen bit (rcon<7>) is ? 0 ?, the peie bit must be set to enable any of these peripheral interrupts. register 9-7: pie1: peripheral interrupt enable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 pspie: parallel slave port read/write interrupt enable bit (1) 1 = enables the psp read/write interrupt 0 = disables the psp read/write interrupt note 1: available in microcontroller mode only. bit 6 adie : a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rcie : usart receive interrupt enable bit 1 = enables the usart receive interrupt 0 = disables the usart receive interrupt bit 4 txie : usart transmit interrupt enable bit 1 = enables the usart transmit interrupt 0 = disables the usart transmit interrupt bit 3 sspie : master synchronous serial port interrupt enable bit 1 = enables the mssp interrupt 0 = disables the mssp interrupt bit 2 ccp1ie : enhanced ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie : tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie : tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 118 ? 2004 microchip technology inc. register 9-8: pie2: peripheral interrupt enable register 2 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ?cmie ? eeie bclie lvdie tmr3ie ccp2ie bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 cmie : comparator interrupt enable bit 1 = enables the comparator interrupt 0 = disables the comparator interrupt bit 5 unimplemented: read as ? 0 ? bit 4 eeie : data eeprom/flash write operation interrupt enable bit 1 = enables the write operation interrupt 0 = disables the write operation interrupt bit 3 bclie : bus collision interrupt enable bit 1 = enables the bus collision interrupt 0 = disables the bus collision interrupt bit 2 lvdie : low-voltage detect interrupt enable bit 1 = enables the low-voltage detect interrupt 0 = disables the low-voltage detect interrupt bit 1 tmr3ie : tmr3 overflow interrupt enable bit 1 = enables the tmr3 overflow interrupt 0 = disables the tmr3 overflow interrupt bit 0 ccp2ie : ccp2 interrupt enable bit 1 = enables the ccp2 interrupt 0 = disables the ccp2 interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 119 pic18f6585/8585/6680/8680 register 9-9: pie3: peripheral interrupt enable register 3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txb2ie/ txbnie txb1ie (1) txb0ie (1) rxb1ie/ rxbnie rxb0ie/ fifowmie bit 7 bit 0 bit 7 irxie: can invalid received message interrupt enable bit 1 = enable invalid message received interrupt 0 = disable invalid message received interrupt bit 6 wakie: can bus activity wake-up interrupt enable bit 1 = enable bus activity wake-up interrupt 0 = disable bus activity wake-up interrupt bit 5 errie: can bus error interrupt enable bit 1 = enable can bus error interrupt 0 = disable can bus error interrupt bit 4 when can is in mode 0: txb2ie: can transmit buffer 2 interrupt enable bit 1 = enable transmit buffer 2 interrupt 0 = disable transmit buffer 2 interrupt when can is in mode 1 or 2: txbnie: can transmit buffer interrupts enable bit 1 = enable transmit buffer interrupt; individual interrupt is enabled by txbie and bie0 0 = disable all transmit buffer interrupts bit 3 txb1ie: can transmit buffer 1 interrupt enable bit (1) 1 = enable transmit buffer 1 interrupt 0 = disable transmit buffer 1 interrupt bit 2 txb0ie: can transmit buffer 0 interrupt enable bit (1) 1 = enable transmit buffer 0 interrupt 0 = disable transmit buffer 0 interrupt bit 1 when can is in mode 0: rxb1ie: can receive buffer 1 interrupt enable bit 1 = enable receive buffer 1 interrupt 0 = disable receive buffer 1 interrupt when can is in mode 1 or 2: rxbnie: can receive buffer interrupts enable bit 1 = enable receive buffer interrupt; individual interrupt is enabled by bie0 0 = disable all receive buffer interrupts bit 0 when can is in mode 0: rxb0ie: can receive buffer 0 interrupt enable bit 1 = enable receive buffer 0 interrupt 0 = disable receive buffer 0 interrupt when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmie: fifo watermark interrupt enable bit 1 = enable fifo watermark interrupt 0 = disable fifo watermark interrupt note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 120 ? 2004 microchip technology inc. 9.4 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt priority registers (ipr1, ipr2 and ipr3). the operation of the priority bits requires that the interrupt priority enable (ipen) bit be set. register 9-10: ipr1: peripheral interrupt priority register 1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip bit 7 bit 0 bit 7 pspip: parallel slave port read/write interrupt priority bit (1) 1 = high priority 0 = low priority note 1: available in microcontroller mode only. bit 6 adip : a/d converter interrupt priority bit 1 = high priority 0 = low priority bit 5 rcip : usart receive interrupt priority bit 1 = high priority 0 = low priority bit 4 txip : usart transmit interrupt priority bit 1 = high priority 0 = low priority bit 3 sspip : master synchronous serial port interrupt priority bit 1 = high priority 0 = low priority bit 2 ccp1ip : ccp1 interrupt priority bit 1 = high priority 0 = low priority bit 1 tmr2ip : tmr2 to pr2 match interrupt priority bit 1 = high priority 0 = low priority bit 0 tmr1ip : tmr1 overflow interrupt priority bit 1 = high priority 0 = low priority legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 121 pic18f6585/8585/6680/8680 register 9-11: ipr2: peripheral interrupt priority register 2 u-0 r/w-1 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ?cmip ? eeip bclip lvdip tmr3ip ccp2ip bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 cmip : comparator interrupt priority bit 1 = high priority 0 = low priority bit 5 unimplemented: read as ? 0 ? bit 4 eeip : data eeprom/flash write operation interrupt priority bit 1 = high priority 0 = low priority bit 3 bclip : bus collision interrupt priority bit 1 = high priority 0 = low priority bit 2 lvdip : low-voltage detect interrupt priority bit 1 = high priority 0 = low priority bit 1 tmr3ip : tmr3 overflow interrupt priority bit 1 = high priority 0 = low priority bit 0 ccp2ip : ccp2 interrupt priority bit 1 = high priority 0 = low priority legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 122 ? 2004 microchip technology inc. register 9-12: ipr3: peripheral interrupt priority register 3 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txb2ip/ txbnip txb1ip (1) txb0ip (1) rxb1ip/ rxbnip rxb0ip/ fifowmip bit 7 bit 0 bit 7 irxip: can invalid received message interrupt priority bit 1 = high priority 0 = low priority bit 6 wakip: can bus activity wake-up interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can bus error interrupt priority bit 1 = high priority 0 = low priority bit 4 when can is in mode 0: txb2ip: can transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: txbnip: can transmit buffer interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: can transmit buffer 1 interrupt priority bit (1) 1 = high priority 0 = low priority bit 2 txb0ip: can transmit buffer 0 interrupt priority bit (1) 1 = high priority 0 = low priority bit 1 when can is in mode 0: rxb1ip: can receive buffer 1 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: rxbnip: can receive buffer interrupts priority bit 1 = high priority 0 = low priority bit 0 when can is in mode 0: rxb0ip: can receive buffer 0 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmip: fifo watermark interrupt priority bit 1 = high priority 0 = low priority note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 123 pic18f6585/8585/6680/8680 9.5 rcon register the rcon register contains the ipen bit which is used to enable prioritized interrupts. the functions of the other bits in this register are discussed in more detail in section 4.14 ?rcon register? . register 9-13: rcon register r/w-0 u-0 u-0 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen ? ?ri to pd por bor bit 7 bit 0 bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16 compatibility mode) bit 6-5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit for details of bit operation, see register 4-4. bit 3 to : watchdog time-out flag bit for details of bit operation, see register 4-4. bit 2 pd : power-down detection flag bit for details of bit operation, see register 4-4. bit 1 por : power-on reset status bit for details of bit operation, see register 4-4. bit 0 bor : brown-out reset status bit for details of bit operation, see register 4-4. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 124 ? 2004 microchip technology inc. 9.6 int0 interrupt external interrupts on the rb0/int0, rb1/int1, rb2/ int2 and rb3/int3 pins are edge-triggered: either ris- ing if the corresponding intedgx bit is set in the intcon2 register, or falling if the intedgx bit is clear. when a valid edge appears on the rbx/intx pin, the corresponding flag bit, intxf, is set. this interrupt can be disabled by clearing the corresponding enable bit, intxe. flag bit, intxf, must be cleared in software in the interrupt service routine before re-enabling the interrupt. all external interrupts (int0, int1, int2 and int3) can wake-up the processor from sleep if bit intxie was set prior to going into sleep. if the global interrupt enable bit gie is set, the processor will branch to the interrupt vector following wake-up. the interrupt priority for int, int2 and int3 is deter- mined by the value contained in the interrupt priority bits: int1ip (intcon3<6>), int2ip (intcon3<7>) and int3ip (intcon2<1>). there is no priority bit associated with int0; it is always a high priority interrupt source. 9.7 tmr0 interrupt in 8-bit mode (which is the default), an overflow in the tmr0 register (0ffh 00h) will set flag bit tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l regis- ters (0ffffh 0000h) will set flag bit, tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit, tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the interrupt priority bit, tmr0ip (intcon2<2>). see section 11.0 ?timer0 module? for further details on the timer0 module. 9.8 portb interrupt-on-change an input change on portb<7:4> sets flag bit rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit, rbie (intcon<3>). interrupt priority for portb interrupt-on-change is determined by the value contained in the interrupt priority bit, rbip (intcon2<0>). 9.9 context saving during interrupts during an interrupt, the return pc value is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 4.3 ?fast register stack? ), the user may need to save the wreg, status and bsr registers in software. depending on the user?s application, other registers may also need to be saved. example 9-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 9-1: saving status, wreg and bsr registers in ram movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
? 2004 microchip technology inc. ds30491c-page 125 pic18f6585/8585/6680/8680 10.0 i/o ports depending on the device selected, there are either seven or nine i/o ports available on pic18f6x8x/8x8x devices. some of their pins are multiplexed with one or more alternate functions from the other peripheral fea- tures on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three registers for its operation. these registers are:  tris register (data direction register)  port register (reads the levels on the pins of the device)  lat register (output latch) the data latch register (lat) is useful for read-modify- write operations on the value that the i/o pins are driving. a simplified version of a generic i/o port and its operation is shown in figure 10-1. figure 10-1: simplified block diagram of port/lat/tris operation 10.1 porta, trisa and lata registers porta is a 7-bit wide, bidirectional port. the corre- sponding data direction register is trisa. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it will write to the port latch. the data latch register (lata) is also memory mapped. read-modify-write operations on the lata register read and write the latched output value for porta. the ra4 pin is multiplexed with the timer0 module clock input to become the ra4/t0cki pin. the ra4/t0cki pin is a schmitt trigger input and an open- drain output. all other ra port pins have ttl input levels and full cmos output drivers. the ra6 pin is only enabled as a general i/o pin in ecio and rcio oscillator modes. the other porta pins are multiplexed with analog inputs and the analog v ref + and v ref - inputs. the operation of each pin is selected by clearing/setting the control bits in the adcon1 register (a/d control register 1). the trisa register controls the direction of the ra pins even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 10-1: initializing porta q d ck wr lat + data latch i/o pin rd port wr port tris rd lat data bus note: on a power-on reset, ra5 and ra3:ra0 are configured as analog inputs and read as ? 0 ?. ra6 and ra4 are configured as digital inputs. clrf porta ; initialize porta by ; clearing output ; data latches clrf lata ; alternate method ; to clear output ; data latches movlw 0fh ; configure a/d movwf adcon1 ; for digital inputs movlw 0cfh ; value used to ; initialize data ; direction movwf trisa ; set ra<3:0> as inputs ; ra<5:4> as outputs
pic18f6585/8585/6680/8680 ds30491c-page 126 ? 2004 microchip technology inc. figure 10-2: block diagram of ra3:ra0 and ra5 pins figure 10-3: block diagram of ra4/t0cki pin figure 10-4: block diagram of ra6 pin (when enabled as i/o) data bus q d q ck q d q ck qd en p n wr lata wr trisa data latch tris latch rd trisa rd porta v ss v dd i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss . analog input mode ttl input buffer to a/d converter and lvd modules rd lata or porta data bus wr trisa rd porta data latch tris latch schmitt trigger input buffer n v ss i/o pin (1) tmr0 clock input q d q ck q d q ck en qd en rd lata wr lata or porta rd trisa note 1: i/o pins have protection diodes to v dd and v ss . data bus q d q ck qd en p n wr lata wr data latch tris latch rd rd porta v ss v dd i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss . or porta rd lata ecra6 or ttl input buffer ecra6 or rcra6 enable rcra6 enable trisa q d q ck trisa
? 2004 microchip technology inc. ds30491c-page 127 pic18f6585/8585/6680/8680 table 10-1: porta functions table 10-2: summary of registers associated with porta name bit# buffer function ra0/an0 bit 0 ttl input/output or analog input. ra1/an1 bit 1 ttl input/output or analog input. ra2/an2/v ref - bit 2 ttl input/output or analog input or v ref -. ra3/an3/v ref + bit 3 ttl input/output or analog input or v ref +. ra4/t0cki bit 4 st/od input/output or external clock input for timer0. output is open-drain type. ra5/an4/lvdin bit 5 ttl input/output or slave select input for synchronous serial port or analog input, or low-voltage detect input. osc2/clko/ra6 bit 6 ttl osc2 or clock output, or i/o pin. legend: ttl = ttl input, st = schmitt trigger input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets porta ? ra6 ra5 ra4 ra3 ra2 ra1 ra0 -x0x 0000 -u0u 0000 lata ? lata data output register -xxx xxxx -uuu uuuu trisa ? porta data direction register -111 1111 -111 1111 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by porta.
pic18f6585/8585/6680/8680 ds30491c-page 128 ? 2004 microchip technology inc. 10.2 portb, trisb and latb registers portb is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latb) is also memory mapped. read-modify-write operations on the latb register read and write the latched output value for portb. example 10-2: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit rbpu (intcon2<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. four of the portb pins (rb3:rb0) are the external interrupt pins, int3 through int0. in order to use these pins as external interrupts, the corresponding trisb bit must be set to ? 1 ?. the other four portb pins (rb7:rb4) have an interrupt-on-change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb7:rb4 pin configured as an output is excluded from the interrupt-on-change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are or?ed together to generate the rb port change interrupt with flag bit, rbif (intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb (except with the movff instruction). this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit, rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. for pic18fxx85 devices, rb3 can be configured by the configuration bit, ccp2mx, as the alternate peripheral pin for the ccp2 module. this is only available when the device is configured in micr oprocessor, microprocessor with boot block, or extended microcontroller operating modes. the rb5 pin is used as the lvp programming pin. when the lvp configuration bit is programmed, this pin loses the i/o function and becomes a programming test function. figure 10-5: block diagram of rb7:rb4 pins note: on a power-on reset, these pins are configured as digital inputs. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs note: when lvp is enabled, the weak pull-up on rb5 is disabled. data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr latb wr trisb set rbif tris latch rd trisb rd portb rb7:rb4 pins weak pull-up rd portb latch ttl input buffer st buffer rb7:rb5 in serial programming mode q3 q1 rd latb or portb note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (intcon2<7>).
? 2004 microchip technology inc. ds30491c-page 129 pic18f6585/8585/6680/8680 figure 10-6: block diagram of rb2:rb0 pins figure 10-7: block diagram of rb3 pin data latch rbpu (2) p v dd q d ck q d ck qd en data bus wr port wr tris rd tris rd port weak pull-up rd port intx i/o pin (1) ttl input buffer schmitt trigger buffer tris latch note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (option_reg<7>). data latch p v dd q d ck q d en data bus wr latb or wr trisb rd trisb rd portb weak pull-up ccp2 or int3 ttl input buffer schmitt trigger buffer tris latch rd latb wr portb rbpu (2) ck d enable (3) ccp output rd portb ccp output (3) 1 0 p n v dd v ss i/o pin (1) q ccp2mx ccp2mx = 0 note 1: i/o pin has diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (intcon2<7>). 3: for pic18fxx85 parts, the ccp2 input/output is multiplexed with rb3 if the ccp2mx bit is enabled (= 0 ) in the configuration register and the device is operating in microprocessor, microprocessor with boot block or extended microcontroller mode.
pic18f6585/8585/6680/8680 ds30491c-page 130 ? 2004 microchip technology inc. table 10-3: portb functions table 10-4: summary of registers associated with portb name bit# buffer function rb0/int0 bit 0 ttl/st (1) input/output pin or external interrupt input 0. internal software programmable weak pull-up. rb1/int1 bit 1 ttl/st (1) input/output pin or external interrupt input 1. internal software programmable weak pull-up. rb2/int2 bit 2 ttl/st (1) input/output pin or external interrupt input 2. internal software programmable weak pull-up. rb3/int3/ccp2 (3) bit 3 ttl/st (4) input/output pin or external interrupt input 3. capture 2 input/ compare 2 output/pwm output (when ccp2mx configuration bit is enabled, all pic18fxx85 operating modes except microcontroller mode). internal software programmable weak pull-up. rb4/kbi0 bit 4 ttl input/output pin (with interrupt-on-change). internal software programmable weak pull-up. rb5/kbi1/pgm bit 5 ttl/st (2) input/output pin (with interrupt-on-change). internal software programmable weak pull-up. low-voltage icsp enable pin. rb6/kbi2/pgc bit 6 ttl/st (2) input/output pin (with interrupt-on-change). internal software programmable weak pull-up. serial programming clock. rb7/kbi3/pgd bit 7 ttl/st (2) input/output pin (with interrupt-on-change). internal software programmable weak pull-up. serial programming data. legend: ttl = ttl input, st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: rc1 is the alternate assignment for ccp2 when ccp2mx is not set (all operating modes except microcontroller mode). 4: this buffer is a schmitt trigger input when configured as the ccp2 input. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu latb latb data output register xxxx xxxx uuuu uuuu trisb portb data direction register 1111 1111 1111 1111 intcon gie/ gieh peie/ giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 1111 1111 1111 1111 intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 1100 0000 1100 0000 legend: x = unknown, u = unchanged. shaded cells are not used by portb.
? 2004 microchip technology inc. ds30491c-page 131 pic18f6585/8585/6680/8680 10.3 portc, trisc and latc registers portc is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisc. setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latc) is also memory mapped. read-modify-write operations on the latc register read and write the latched output value for portc. portc is multiplexed with several peripheral functions (table 10-5). portc pins have schmitt trigger input buffers. when enabling peripheral functions, care should be taken in defining tris bits for each portc pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corre- sponding peripheral section for the correct tris bit settings. the pin override value is not loaded into the tris reg- ister. this allows read-modify-write of the tris register without concern due to peripheral overrides. rc1 is normally configured by configuration bit, ccp2mx, as the default peripheral pin of the ccp2 module (default/erased state, ccp2mx = 1 ). example 10-3: initializing portc figure 10-8: portc block diagram (peripheral output override) note: on a power-on reset, these pins are configured as digital inputs. clrf portc ; initialize portc by ; clearing output ; data latches clrf latc ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisc ; set rc<3:0> as inputs ; rc<5:4> as outputs ; rc<7:6> as inputs portc/peripheral out select data bus wr latc wr trisc data latch tris latch rd trisc q d q ck qd en peripheral data out 0 1 q d q ck p n v dd v ss rd portc peripheral data in i/o pin (1) or wr portc rd latc schmitt trigger note 1: i/o pins have diode protection to v dd and v ss . 2: peripheral output enable is only active if peripheral select is active. tris override peripheral output logic tris override pin override peripheral rc0 yes timer1 osc for timer1/timer3 rc1 yes timer1 osc for timer1/timer3, ccp2 i/o rc2 yes ccp1 i/o rc3 yes spi/i 2 c master clock rc4 yes i 2 c data out rc5 yes spi data out rc6 yes usart async xmit, sync clock rc7 yes usart sync data out enable (2)
pic18f6585/8585/6680/8680 ds30491c-page 132 ? 2004 microchip technology inc. table 10-5: portc functions table 10-6: summary of registers associated with portc name bit# buffer type function rc0/t1oso/t13cki bit 0 st input/output port pin, timer1 oscillator output or timer1/timer3 clock input. rc1/t1osi/ccp2 (1) bit 1 st input/output port pin, timer1 oscillator input or capture 2 input/ compare 2 output/pwm output (when ccp2mx configuration bit is disabled). rc2/ccp1/p1a bit 2 st input/output port pin or capture 1 input/compare 1 output/ pwm1 output. rc3/sck/scl bit 3 st rc3 can also be the synchronous serial clock for both spi and i 2 c modes. rc4/sdi/sda bit 4 st rc4 can also be the spi data in (spi mode) or data i/o (i 2 c mode). rc5/sdo bit 5 st input/output port pin or synchronous serial port data output. rc6/tx/ck bit 6 st input/output port pin, addressable usart asynchronous transmit or addressable usart synchronous clock. rc7/rx/dt bit 7 st input/output port pin, addressable usart asynchronous receive or addressable usart synchronous data. legend: st = schmitt trigger input note 1: rb3 is the alternate assignment for ccp2 when ccp2mx is set. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu latc latc data output register xxxx xxxx uuuu uuuu trisc portc data direction register 1111 1111 1111 1111 legend: x = unknown, u = unchanged
? 2004 microchip technology inc. ds30491c-page 133 pic18f6585/8585/6680/8680 10.4 portd, trisd and latd registers portd is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisd. setting a trisd bit (= 1 ) will make the corresponding portd pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisd bit (= 0 ) will make the corresponding portd pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latd) is also memory mapped. read-modify-write operations on the latd register read and write the latched output value for portd. portd is an 8-bit port with schmitt trigger input buffers. each pin is individually configurable as an input or output. on pic18f8x8x devices, portd is multiplexed with the system bus as the external memory interface; i/o port functions are only available when the system bus is disabled by setting the ebdis bit in the memcom register (memcon<7>). when operating as the exter- nal memory interface, portd is the low-order byte of the multiplexed address/data bus (ad7:ad0). portd can also be configured as an 8-bit wide micro- processor port (parallel slave port) by setting control bit, pspmode (trise<4>). in this mode, the input buffers are ttl. see section 10.10 ?parallel slave port (psp)? for additional information. example 10-4: initializing portd figure 10-9: port d block diagram in i/o port mode note: on a power-on reset, these pins are configured as digital inputs. clrf portd ; initialize portd by ; clearing output ; data latches clrf latd ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisd ; set rd<3:0> as inputs ; rd<5:4> as outputs ; rd<7:6> as inputs data bus wr latd wr trisd rd portd data latch tris latch rd trisd schmitt trigger input buffer i/o pin (1) q d ck q d ck en qd en rd latd or portd note 1: i/o pins have diode protection to v dd and v ss .
pic18f6585/8585/6680/8680 ds30491c-page 134 ? 2004 microchip technology inc. figure 10-10: portd block diagram in system bus mode (pic18f8x8x only) instruction register bus enable data/tris out drive bus system bus control data bus wr latd wr trisd rd portd data latch tris latch rd trisd ttl input buffer i/o pin (1) q d ck q d ck en qd en rd latd or portd 0 1 port data instruction read note 1: i/o pins have protection diodes to v dd and v ss .
? 2004 microchip technology inc. ds30491c-page 135 pic18f6585/8585/6680/8680 table 10-7: portd functions table 10-8: summary of registers associated with portd name bit# buffer type function rd0/psp0/ad0 (2) bit 0 st/ttl (1) input/output port pin, parallel slave port bit 0 or address/data bus bit 0. rd1/psp1/ad1 (2) bit 1 st/ttl (1) input/output port pin, parallel slave port bit 1 or address/data bus bit 1. rd2/psp2/ad2 (2) bit 2 st/ttl (1) input/output port pin, parallel slave port bit 2 or address/data bus bit 2. rd3/psp3/ad3 (2) bit 3 st/ttl (1) input/output port pin, parallel slave port bit 3 or address/data bus bit 3. rd4/psp4/ad4 (2) bit 4 st/ttl (1) input/output port pin, parallel slave port bit 4 or address/data bus bit 4. rd5/psp5/ad5 (2) bit 5 st/ttl (1) input/output port pin, parallel slave port bit 5 or address/data bus bit 5. rd6/psp6/ad6 (2) bit 6 st/ttl (1) input/output port pin, parallel slave port bit 6 or address/data bus bit 6. rd7/psp7/ad7 (2) bit 7 st/ttl (1) input/output port pin, parallel slave port bit 7 or address/data bus bit 7. legend: st = schmitt trigger input, ttl = ttl input note 1: input buffers are schmitt triggers when in i/o mode and ttl buffers when in system bus or parallel slave port mode. 2: available in pic18f8x8x devices only. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx uuuu uuuu latd latd data output register xxxx xxxx uuuu uuuu trisd portd data direction register 1111 1111 1111 1111 pspcon ibf obf ibov pspmode ? ? ? ? 0000 ---- 0000 ---- memcon ebdis ? wait1 wait0 ? ? wm1 wm0 0-00 --00 0-00 --00 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by portd.
pic18f6585/8585/6680/8680 ds30491c-page 136 ? 2004 microchip technology inc. 10.5 porte, trise and late registers porte is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trise. setting a trise bit (= 1 ) will make the corresponding porte pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trise bit (= 0 ) will make the corresponding porte pin an output (i.e., put the contents of the output latch on the selected pin). read-modify-write operations on the late register read and write the latched output value for porte. porte is an 8-bit port with schmitt trigger input buffers. each pin is individually configurable as an input or output. porte is multiplexed with the enhanced ccp module (table 10-9). on pic18f8x8x devices, porte is also multiplexed with the system bus as the external memory interface; the i/o bus is available only when the system bus is disabled by setting the ebdis bit in the memcon register (memcon<7>). if the device is configured in microprocessor or extended microcontroller mode, then the porte<7:0> becomes the high byte of the address/ data bus for the external program memory interface. in microcontroller mode, the porte<2:0> pins become the control inputs for the parallel slave port when bit pspmode (pspcon<4>) is set. (refer to section 4.1.1 ?pic18f8x8x program memory modes? for more information on program memory modes.) when the parallel slave port is active, three porte pins (re0/rd /ad8, re1/wr /ad9 and re2/cs /ad10) function as its control inputs. this automatically occurs when the pspmode bit (pspcon<4>) is set. users must also make certain that bits trise<2:0> are set to configure the pins as digital inputs and the adcon1 register is configured for digital i/o. the porte psp control functions are summarized in table 10-9. pin re7 can be configured as the alternate peripheral pin for the ccp2 module when the device is operating in microcontroller mode. this is done by clearing the configuration bit, ccp2mx, in configuration register, config3h (config3h<0>). example 10-5: initializing porte note: for pic18f8x8x (80-pin) devices operat- ing in other than microcontroller mode, porte defaults to the system bus on power-on reset. clrf porte ; initialize porte by ; clearing output ; data latches clrf late ; alternate method ; to clear output ; data latches movlw 03h ; value used to ; initialize data ; direction movwf trise ; set re1:re0 as inputs ; re7:re2 as outputs
? 2004 microchip technology inc. ds30491c-page 137 pic18f6585/8585/6680/8680 figure 10-11: porte block diagram in i/o mode figure 10-12: porte block diagram in system bus mode (pic18f8x8x only) peripheral out select data bus wr late wr trise data latch tris latch rd trise q d q ck qd en peripheral data out 0 1 q d q ck p n v dd v ss rd porte peripheral data in i/o pin (1) or wr porte rd late schmitt trigger note 1: i/o pins have diode protection to v dd and v ss . tris override peripheral enable tris override pin override peripheral re0 yes external bus re1 yes external bus re2 yes external bus re3 yes external bus re4 yes external bus re5 yes external bus re6 yes external bus re7 yes external bus instruction register bus enable data/tris out drive bus system bus control data bus wr late wr trise rd porte data latch tris latch rd trise ttl input buffer i/o pin (1) q d ck q d ck en qd en rd late or porte 0 1 port data instruction read note 1: i/o pins have protection diodes to v dd and v ss .
pic18f6585/8585/6680/8680 ds30491c-page 138 ? 2004 microchip technology inc. table 10-9: porte functions table 10-10: summary of registers associated with porte name bit# buffer type function re0/rd /ad8 (2) bit 0 st/ttl (1) input/output port pin, read control for parallel slave port or address/data bit 8. for rd (psp control mode): 1 = not a read operation 0 = read operation, reads portd register (if chip selected) re1/wr /ad9 (2) bit 1 st/ttl (1) input/output port pin, write control for parallel slave port or address/data bit 9. for wr (psp control mode): 1 = not a write operation 0 = write operation, writes portd register (if chip selected) re2/cs /ad10 (2) bit 2 st/ttl (1) input/output port pin, chip select control for parallel slave port or address/data bit 10. for cs (psp control mode): 1 = device is not selected 0 = device is selected re3/ad11 (2) bit 3 st/ttl (1) input/output port pin or address/data bit 11. re4/ad12 (2) bit 4 st/ttl (1) input/output port pin or address/data bit 12. re5/ad13/ (2) p1c (3) bit 5 st/ttl (1) input/output port pin, address/data bit 13 or eccp1 pwm output c. re6/ad14/ (2) p1b (3) bit 6 st/ttl (1) input/output port pin, address/data bit 13 or eccp1 pwm output b. re7/ccp2/ad15 (2) bit 7 st/ttl (1) input/output port pin, capture 2 input/compare 2 output/pwm output (pic18f8x20 devices in microcontroller mode only) or address/data bit 15. legend: st = schmitt trigger input, ttl = ttl input note 1: input buffers are schmitt triggers when in i/o or ccp mode, and ttl buffers when in system bus or psp control mode. 2: available in pic18f8x8x devices only. 3: on pic18f8x8x devices, these pins may be moved to rhy or rh6 by changing the eccpmx configuration bit. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets trise porte data direction control register 1111 1111 1111 1111 porte read porte pin/write porte data latch xxxx xxxx uuuu uuuu late read porte data latch/write porte data latch xxxx xxxx uuuu uuuu memcon ebdis ? wait1 wait0 ? ? wm1 wm0 0-00 --00 0000 --00 pspcon ibf obf ibov pspmode ? ? ? ? 0000 ---- 0000 ---- legend: x = unknown, u = unchanged. shaded cells are not used by porte.
? 2004 microchip technology inc. ds30491c-page 139 pic18f6585/8585/6680/8680 10.6 portf, latf and trisf registers portf is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisf. setting a trisf bit (= 1 ) will make the corresponding portf pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisf bit (= 0 ) will make the corresponding portf pin an output (i.e., put the contents of the output latch on the selected pin). read-modify-write operations on the latf register read and write the latched output value for portf. portf is multiplexed with several analog peripheral functions, including the a/d converter inputs and comparator inputs, outputs, and voltage reference. example 10-6: initializing portf figure 10-13: portf rf1/an6/c2out and rf2/an7 /c1out pins block diagram note 1: on a power-on reset, the rf6:rf0 pins are configured as inputs and read as ? 0 ?. 2: to configure portf as digital i/o, turn off comparators and set adcon1 value. clrf portf ; initialize portf by ; clearing output ; data latches clrf latf ; alternate method ; to clear output ; data latches movlw 07h ; movwf cmcon ; turn off comparators movlw 0fh ; movwf adcon1 ; set portf as digital i/o movlw 0cfh ; value used to ; initialize data ; direction movwf trisf ; set rf3:rf0 as inputs ; rf5:rf4 as outputs ; rf7:rf6 as inputs port/comparator select data bus wr latf or wr trisf data latch tris latch rd trisf q d q ck qd en comparator data out 0 1 q d q ck p n v dd v ss rd portf i/o pin wr portf rd latf schmitt trigger note 1: i/o pins have diode protection to v dd and v ss . analog input mode to a/d converter
pic18f6585/8585/6680/8680 ds30491c-page 140 ? 2004 microchip technology inc. figure 10-14: rf6:rf3 and rf0 pins block diagram figure 10-15: rf7 pin block diagram data bus q d q ck q d q ck qd en p n wr latf wr trisf data latch tris latch rd trisf rd portf v ss v dd i/o pin analog input mode st input buffer to a/d converter or comparator input rd latf or wr portf note 1: i/o pins have diode protection to v dd and v ss . data bus wr latf wr trisf rd portf data latch tris latch rd trisf schmitt trigger input buffer i/o pin q d ck q d ck en qd en rd latf or wr portf note: i/o pins have diode protection to v dd and v ss . ttl input buffer ss input
? 2004 microchip technology inc. ds30491c-page 141 pic18f6585/8585/6680/8680 table 10-11: portf functions table 10-12: summary of registers associated with portf name bit# buffer type function rf0/an5 bit 0 st input/output port pin or analog input. rf1/an6/c2out bit 1 st input/output port pin, analog input or comparator 2 output. rf2/an7/c1out bit 2 st input/output port pin, analog input or comparator 1 output. rf3/an8/c2in+ bit 3 st input/output port pin, analog input or comparator 2 input (+). rf4/an9/c2in- bit 4 st input/output port pin, analog input or comparator 2 input (-). rf5/an10/ c1in+/cv ref bit 5 st input/output port pin, analog input, comparator 1 input (+) or comparator reference output. rf6/an11/c1in- bit 6 st input/output port pin, analog input or comparator 1 input (-). rf7/ss bit 7 st/ttl input/output port pin or slave select pin for synchronous serial port. legend: st = schmitt trigger input, ttl = ttl input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets trisf portf data direction control register 1111 1111 1111 1111 portf read portf pin/write portf data latch xxxx xxxx uuuu uuuu latf read portf data latch/write portf data latch 0000 0000 uuuu uuuu adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0000 --00 0000 cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 cvrcon cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 0000 0000 0000 legend: x = unknown, u = unchanged. shaded cells are not used by portf.
pic18f6585/8585/6680/8680 ds30491c-page 142 ? 2004 microchip technology inc. 10.7 portg, trisg and latg registers portg is a 6-bit wide port with 5 bidirectional pins and 1 unidirectional pin. the corresponding data direction register is trisg. setting a trisg bit (= 1 ) will make the corresponding portg pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisg bit (= 0 ) will make the corre- sponding portg pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latg) is also memory mapped. read-modify-write operations on the latg register read and write the latched output value for portg. pins rg0-rg2 on portg are multiplexed with the can peripheral. refer to section 23.0 ?ecan module? for proper settings of trisg when can is enabled. rg5 is multiplexed with mclr /v pp . refer to register 24-5 for more information. when enabling peripheral functions, care should be taken in defining tris bits for each portg pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for the correct tris bit settings. the pin override value is not loaded into the tris reg- ister. this allows read-modify-write of the tris register without concern due to peripheral overrides. example 10-7: initializing port figure 10-16: rg0/cantx1 pin block diagram note: on a power-on reset, these pins are configured as digital inputs. note 1: on a power-on reset, rg5 is enabled as a digital input only if master clear functionality is disabled (mclre = 0 ). 2: if the device master clear is disabled, verify that either of the following is done to ensure proper entry into icsp mode: a) disable low-voltage programming (config4l<2> = 0 ); or b) make certain that rb5/kbi1/pgm is held low during entry into icsp. clrf portg ; initialize portg by ; clearing output ; data latches clrf latg ; alternate method ; to clear output ; data latches movlw 04h ; value used to ; initialize data ; direction movwf trisg ; set rg1:rg0 as outputs ; rg2 as input ; rg4:rg3 as inputs data latch tris latch rd trisg p v ss q d q ck q d q ck en qd en n v dd 0 1 rd portg wr trisg data bus i/o pin txd endrhi opmode2:opmode0 = 000 schmitt trigger rd latg wr portg or wr latg opmode2:opmode0 = 000 note: i/o pins have diode protection to v dd and v ss .
? 2004 microchip technology inc. ds30491c-page 143 pic18f6585/8585/6680/8680 figure 10-17: rg1/cantx2 pin block diagram figure 10-18: rg2/canrx pin block diagram figure 10-19: rg3 pin block diagram data latch tris latch rd trisg p v ss q d q ck q d q ck qd en n v dd 0 1 wr portg or wr trisg data bus rd portg i/o pin 0 1 txd canclk tx1src endrhi opmode2:opmode0 = 000 tx2en schmitt trigger rd latg wr latg opmode2:opmode0 = 000 note: i/o pins have diode protection to v dd and v ss . data bus wr latg wr trisg rd portg data latch tris latch rd trisg i/o pin q d ck q d ck en qd en rd latg or wr portg canrx schmitt trigger input buffer note: i/o pins have diode protection to v dd and v ss . data bus wr latg wr trisg rd portg data latch tris latch rd trisg schmitt trigger input buffer i/o pin q d ck q d ck en qd en rd latg or wr portg note: i/o pins have diode protection to v dd and v ss .
pic18f6585/8585/6680/8680 ds30491c-page 144 ? 2004 microchip technology inc. figure 10-20: rg4/p1d pin block diagram figure 10-21: rg5/mclr /v pp pin block diagram data bus wr latg wr trisg rd portg data latch tris latch rd trisg schmitt trigger input buffer i/o pin q d ck q d ck en qd en rd latg or wr portg 1 0 ccp1 p1d enable p1d out auto-shutdown note: i/o pins have diode protection to v dd and v ss . rg5/mclr /v pp data bus rd porta rd lata schmitt trigger mclre rd trisa qd en latch filter low-level mclr detect high-voltage detect internal mclr hv
? 2004 microchip technology inc. ds30491c-page 145 pic18f6585/8585/6680/8680 table 10-13: portg functions table 10-14: summary of registers associated with portg name bit# buffer type function rg0/cantx1 bit 0 st input/output port pin or can bus transmit output. rg1/cantx2 bit 1 st input/output port pin, can bus complimentary transmit output or can bus bit time clock. rg2/canrx bit 2 st input/output port pin or can bus receive. rg3 bit 3 st input/output port pin. rg4/p1d bit 4 st input/output port pin or eccp1 pwm output d. rg5/mclr /v pp bit 5 st master clear input or programming voltage input (if mclr is enabled). input only port pin or programming voltage input (if mclr is disabled). legend: st = schmitt trigger input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portg ? ?rg5 (1) read portf pin/write portf data latch --0x xxxx --0u uuuu latg ? ? ? latg data output register ---x xxxx ---u uuuu trisg ? ? ? data direction control register for portg ---1 1111 ---1 1111 legend: x = unknown, u = unchanged note 1: rg5 is available as an input only when mclr is disabled.
pic18f6585/8585/6680/8680 ds30491c-page 146 ? 2004 microchip technology inc. 10.8 porth, lath and trish registers porth is an 8-bit wide, bidirectional i/o port. the cor- responding data direction register is trish. setting a trish bit (= 1 ) will make the corresponding porth pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trish bit (= 0 ) will make the corresponding porth pin an output (i.e., put the contents of the output latch on the selected pin). read-modify-write operations on the lath register read and write the latched output value for porth. pins rh7:rh4 are multiplexed with analog inputs an15:an12. pins rh3:rh0 are multiplexed with the system bus as the external memory interface; they are the high-order address bits, a19:a16. by default, pins rh7:rh4 are enabled as a/d inputs and pins rh3:rh0 are enabled as the system address bus. register adcon1 configures rh7:rh4 as i/o or a/d inputs. register memcon configures rh3:rh0 as i/o or system bus pins. pins rh7 and rh6 can be configured as the alternate peripheral pins for ccp1 pwm output p1b and p1c, respectively. this is done by clearing the configuration bit eccpmx, in configuration register config3h (config3h<1>). example 10-8: initializing porth figure 10-22: rh3:rh0 pins block diagram in i/o mode figure 10-23: rh7:rh4 pins block diagram in i/o mode note: porth is available only on pic18f8x8x devices. note 1: on power-on reset, porth pins rh7:rh4 default to a/d inputs and read as ? 0 ?. 2: on power-on reset, porth pins rh3:rh0 default to system bus signals. clrf porth ; initialize porth by ; clearing output ; data latches clrf lath ; alternate method ; to clear output ; data latches movlw 0fh ; movwf adcon1 ; movlw 0cfh ; value used to ; initialize data ; direction movwf trish ; set rh3:rh0 as inputs ; rh5:rh4 as outputs ; rh7:rh6 as inputs data bus wr lath wr trish rd porth data latch tris latch rd trish schmitt trigger input buffer i/o pin (1) q d ck q d ck en qd en rd lath or porth note 1: i/o pins have diode protection to v dd and v ss . data bus wr lath wr trish rd porth data latch tris latch rd trish schmitt trigger input buffer i/o pin (1) q d ck q d ck en qd en rd lath or porth to a/d converter note 1: i/o pins have diode protection to v dd and v ss .
? 2004 microchip technology inc. ds30491c-page 147 pic18f6585/8585/6680/8680 figure 10-24: rh3:rh0 pins bloc k diagram in system bus mode to instruction register external enable address out drive system system bus control data bus wr lath wr trish rd porth data latch tris latch rd trish ttl input buffer i/o pin (1) q d ck q d ck en qd en rd latd or porth 0 1 port data instruction read note 1: i/o pins have diode protection to v dd and v ss .
pic18f6585/8585/6680/8680 ds30491c-page 148 ? 2004 microchip technology inc. table 10-15: porth functions table 10-16: summary of registers associated with porth name bit# buffer type function rh0/a16 bit 0 st/ttl (1) input/output port pin or address bit 16 for external memory interface. rh1/a17 bit 1 st/ttl (1) input/output port pin or address bit 17 for external memory interface. rh2/a18 bit 2 st/ttl (1) input/output port pin or address bit 18 for external memory interface. rh3/a19 bit 3 st/ttl (1) input/output port pin or address bit 19 for external memory interface. rh4/an12 bit 4 st input/output port pin or analog input channel 12. rh5/an13 bit 5 st input/output port pin or analog input channel 13. rh6/an14/p1c (2) bit 6 st input/output port pin or analog input channel 14. rh7/an15/p1b (2) bit 7 st input/output port pin or analog input channel 15. legend: st = schmitt trigger input, ttl = ttl input note 1: input buffers are schmitt triggers when in i/o mode and ttl buffers when in system bus or parallel slave port mode. 2: alternate pin assignment when eccpmx configuration bit is cleared. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets trish porth data direction control register 1111 1111 1111 1111 porth read porth pin/write porth data latch xxxx xxxx uuuu uuuu lath read porth data latch/write porth data latch xxxx xxxx uuuu uuuu adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0000 --00 0000 memcon (1) ebdis ? wait1 wait0 ? ? wm1 wm0 0-00 --00 0-00 --00 legend: x = unknown, u = unchanged, ? = unimplemented. shaded cells are not used by porth. note 1: this register is held in reset in microcontroller mode.
? 2004 microchip technology inc. ds30491c-page 149 pic18f6585/8585/6680/8680 10.9 portj, trisj and latj registers portj is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisj. setting a trisj bit (= 1 ) will make the corresponding portj pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisj bit (= 0 ) will make the corresponding portj pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latj) is also memory mapped. read-modify-write operations on the latj register read and write the latched output value for portj. portj is multiplexed with the system bus as the external memory interface; i/o port functions are only available when the system bus is disabled. when operating as the external memory interface, portj provides the control signal to external memory devices. the rj5 pin is not multiplexed with any system bus functions. when enabling peripheral functions, care should be taken in defining tris bits for each portj pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for the correct tris bit settings. the pin override value is not loaded into the tris reg- ister. this allows read-modify-write of the tris register without concern due to peripheral overrides. example 10-9: initializing portj figure 10-25: portj block diagram in i/o mode note: portj is available only on pic18f8x8x devices. note: on a power-on reset, these pins are configured as digital inputs. clrf portj ; initialize portg by ; clearing output ; data latches clrf latj ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisj ; set rj3:rj0 as inputs ; rj5:rj4 as output ; rj7:rj6 as inputs data bus wr latj wr trisj rd portj data latch tris latch rd trisj schmitt trigger input buffer i/o pin (1) q d ck q d ck en qd en rd latj or portj note 1: i/o pins have diode protection to v dd and v ss .
pic18f6585/8585/6680/8680 ds30491c-page 150 ? 2004 microchip technology inc. figure 10-26: rj5:rj0 pins bl ock diagram in system bus mode figure 10-27: rj7:rj6 pins blo ck diagram in system bus mode external enable control out drive system system bus control data bus wr latj wr trisj rd portj data latch tris latch rd trisj i/o pin (1) q d ck en qd en rd latj or portj 0 1 port data note 1: i/o pins have diode protection to v dd and v ss . q d ck wm = 01 ub /lb out drive system system bus control data bus wr latj wr trisj rd portj data latch tris latch rd trisj i/o pin (1) q d ck en qd en rd latj or portj 0 1 port data note 1: i/o pins have diode protection to v dd and v ss . q d ck
? 2004 microchip technology inc. ds30491c-page 151 pic18f6585/8585/6680/8680 table 10-17: portj functions table 10-18: summary of registers associated with portj name bit# buffer type function rj0/ale bit 0 st input/output port pin or address latch enable control for external memory interface. rj1/oe bit 1 st input/output port pin or output enable control for external memory interface. rj2/wrl bit 2 st input/output port pin or write low byte control for external memory interface. rj3/wrh bit 3 st input/output port pin or write high byte control for external memory interface. rj4/ba0 bit 4 st input/output port pin or byte address 0 control for external memory interface. rj5/ce bit 5 st input/output port pin or external memory chip enable. rj6/lb bit 6 st input/output port pin or lower byte select control for external memory interface. rj7/ub bit 7 st input/output port pin or upper byte select control for external memory interface. legend: st = schmitt trigger input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portj read portj pin/write portj data latch xxxx xxxx uuuu uuuu latj latj data output register xxxx xxxx uuuu uuuu trisj data direction control register for portj 1111 1111 1111 1111 legend: x = unknown, u = unchanged
pic18f6585/8585/6680/8680 ds30491c-page 152 ? 2004 microchip technology inc. 10.10 parallel slave port (psp) portd also operates as an 8-bit wide parallel slave port, or microprocessor port, when control bit pspmode (trise<4>) is set. it is asynchronously readable and writable by the external world through rd control input pin, re0/rd /ad8 and wr control input pin, re1/wr /ad9. the psp can directly interface to an 8-bit micro- processor data bus. the external microprocessor can read or write the portd latch as an 8-bit latch. setting bit pspmode enables port pin re0/rd /ad8 to be the rd input, re1/wr /ad9 to be the wr input and re2/cs /ad10 to be the cs (chip select) input. for this functionality, the corresponding data direction bits of the trise register (trise<2:0>) must be configured as inputs (set). the a/d port configuration bits pcfg2:pcfg0 (adcon1<2:0>) must be set, which will configure pins re2:re0 as digital i/o. a write to the psp occurs when both the cs and wr lines are first detected low. a read from the psp occurs when both the cs and rd lines are first detected low. the porte i/o pins become control inputs for the microprocessor port when bit pspmode (pspcon<4>) is set. in this mode, the user must make sure that the trise<2:0> bits are set (pins are config- ured as digital inputs) and the adcon1 is configured for digital i/o. in this mode, the input buffers are ttl. figure 10-28: portd and porte block diagram (parallel slave port) note: for pic18f8x8x devices, the parallel slave port is available only in microcontroller mode. data bus wr latd rdx q d ck en qd en rd portd pin one bit of portd set interrupt flag pspif (pir1<7>) read chip select write rd cs wr note: i/o pin has protection diodes to v dd and v ss . ttl ttl ttl ttl or portd rd latd data latch tris latch
? 2004 microchip technology inc. ds30491c-page 153 pic18f6585/8585/6680/8680 register 10-1: pspcon register figure 10-29: parallel slave port write waveforms r-0 r-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ibf obf ibov pspmode ? ? ? ? bit 7 bit 0 bit 7 ibf: input buffer full status bit 1 = a data byte has been received and is waiting to be read by the cpu 0 = no data byte has been received bit 6 obf: output buffer full status bit 1 = the output buffer still holds a previously written data byte 0 = the output buffer has been read bit 5 ibov: input buffer overflow detect bit 1 = a write occurred when a previously input data byte has not been read (must be cleared in software) 0 = no overflow occurred bit 4 pspmode: parallel slave port mode select bit 1 = parallel slave port mode 0 = general purpose i/o mode bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr rd ibf obf pspif portd<7:0>
pic18f6585/8585/6680/8680 ds30491c-page 154 ? 2004 microchip technology inc. figure 10-30: parallel slave port read waveforms table 10-19: registers associated with parallel slave port q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr ibf pspif rd obf portd<7:0> name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portd port data latch when written; port pins when read xxxx xxxx uuuu uuuu latd latd data output bits xxxx xxxx uuuu uuuu trisd portd data direction bits 1111 1111 1111 1111 porte re7/ccp2/ ad15 re6/ad14/ p1b re5/ad13/ p1c re4/ ad12 re3/ ad11 re2/cs (1) / ad10 re1/wr (1) / ad9 re0/rd (1) / ad8 xxxx xxxx uuuu uuuu late late data output bits xxxx xxxx uuuu uuuu trise porte data direction bits 1111 1111 1111 1111 pspcon ibf obf ibov pspmode ? ? ? ? 0000 ---- 0000 ---- intcon gie/ gieh peie/ giel tmr0if int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the parallel slave port. note 1: enabled only in microcontroller mode.
? 2004 microchip technology inc. ds30491c-page 155 pic18f6585/8585/6680/8680 11.0 timer0 module the timer0 module has the following features:  software selectable as an 8-bit or 16-bit timer/ counter  readable and writable  dedicated 8-bit software programmable prescaler  clock source selectable to be external or internal  interrupt-on-overflow from 0ffh to 00h in 8-bit mode and 0ffffh to 0000h in 16-bit mode  edge select for external clock figure 11-1 shows a simplified block diagram of the timer0 module in 8-bit mode and figure 11-2 shows a simplified block diagram of the timer0 module in 16-bit mode. the t0con register (register 11-1) is a readable and writable register that controls all the aspects of timer0, including the prescale selection. register 11-1: t0con: timer0 control register note: timer0 is enabled on por. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t08bit : timer0 8-bit/16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5 t0cs : timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned. timer0 clock input bypasses prescaler. 0 = timer0 prescaler is assigned. timer0 clock input comes from prescaler output. bit 2-0 t0ps2:t0ps0 : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 156 ? 2004 microchip technology inc. figure 11-1: timer0 block diagram in 8-bit mode figure 11-2: timer0 block diagram in 16-bit mode note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. ra4/t0cki pin t0se 0 1 0 1 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0 (2 t cy delay) data bus 8 psa t0ps2, t0ps1, t0ps0 set interrupt flag bit tmr0if on overflow 3 note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 0 1 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) data bus<7:0> 8 psa t0ps2, t0ps1, t0ps0 set interrupt flag bit tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l
? 2004 microchip technology inc. ds30491c-page 157 pic18f6585/8585/6680/8680 11.1 timer0 operation timer0 can operate as a timer or as a counter. timer mode is selected by clearing the t0cs bit. in timer mode, the timer0 module will increment every instruction cycle (without prescaler). if the tmr0 regis- ter is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting the t0cs bit. in counter mode, timer0 will increment either on every rising or falling edge of pin ra4/t0cki. the increment- ing edge is determined by the timer0 source edge select bit (t0se). clearing the t0se bit selects the rising edge. restrictions on the external clock input are discussed below. when an external clock input is used for timer0, it must meet certain requirements. the requirements ensure the external clock can be synchronized with the internal phase clock (t osc ). also, there is a delay in the actual incrementing of timer0 after synchronization. 11.2 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not readable or writable. the psa and t0ps2:t0ps0 bits determine the prescaler assignment and prescale ratio. clearing bit psa will assign the prescaler to the timer0 module. when the prescaler is assigned to the timer0 module, prescale values of 1:2, 1:4, ..., 1:256 are selectable. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf tmr0, movwf tmr0, bsf tmr0, x , ..., etc.) will clear the prescaler count. 11.2.1 switching prescaler assignment the prescaler assignment is fully under software control (i.e., it can be changed ?on-the-fly? during program execution). 11.3 timer0 interrupt the tmr0 interrupt is generated when the tmr0 reg- ister overflows from 0ffh to 00h in 8-bit mode, or 0ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if bit. the interrupt can be masked by clearing the tmr0ie bit. the tmr0ie bit must be cleared in software by the timer0 module interrupt service routine before re-enabling this interrupt. the tmr0 interrupt cannot awaken the processor from sleep since the timer is shut-off during sleep. 11.4 16-bit mode timer reads and writes tmr0h is not the high byte of the timer/counter in 16-bit mode, but is actually a buffered version of the high byte of timer0 (refer to figure 11-2). the high byte of the timer0 counter/timer is not directly readable nor writable. tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this pro- vides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid due to a rollover between successive reads of the high and low byte. a write to the high byte of timer0 must also take place through the tmr0h buffer register. timer0 high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. table 11-1: registers associated with timer0 note: writing to tmr0 when the prescaler is assigned to timer0 will clear the prescaler count but will not change the prescaler assignment. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets tmr0l timer0 module low byte register xxxx xxxx uuuu uuuu tmr0h timer0 module high byte register 0000 0000 0000 0000 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 1111 1111 1111 1111 trisa ? porta data direction register -111 1111 -111 1111 legend: x = unknown, u = unchanged, ? = unimplemented locations, read as ? 0 ?. shaded cells are not used by timer0.
pic18f6585/8585/6680/8680 ds30491c-page 158 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 159 pic18f6585/8585/6680/8680 12.0 timer1 module the timer1 module timer/counter has the following features:  16-bit timer/counter (two 8-bit registers; tmr1h and tmr1l)  readable and writable (both registers)  internal or external clock select  interrupt on overflow from 0ffffh to 0000h  reset from ccp module special event trigger figure 12-1 is a simplified block diagram of the timer1 module. register 12-1 details the timer1 control register. this register controls the operating mode of the timer1 module and contains the timer1 oscillator enable bit (t1oscen). timer1 can be enabled or disabled by setting or clearing control bit, tmr1on (t1con<0>). register 12-1: t1con: timer1 control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rd16 ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer1 in one 16-bit operation 0 = enables register read/write of timer1 in two 8-bit operations bit 6 unimplemented: read as ? 0 ? bit 5-4 t1ckps1:t1ckps0 : timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: timer1 oscillator enable bit 1 = timer1 oscillator is enabled 0 = timer1 oscillator is shut-off the oscillator inverter and feedback resistor are turned off to eliminate power drain. bit 2 t1sync : timer1 external clock input synchronization select bit when tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from pin rc0/t1oso/t13cki (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 160 ? 2004 microchip technology inc. 12.1 timer1 operation timer1 can operate in one of these modes: as a timer  as a synchronous counter  as an asynchronous counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). when tmr1cs = 0 , timer1 increments every instruc- tion cycle. when tmr1cs = 1 , timer1 increments on every rising edge of the external clock input or the timer1 oscillator if enabled. when the timer1 oscillator is enabled (t1oscen is set), the rc1/t1osi and rc0/t1oso/t13cki pins become inputs. that is, the trisc<1:0> value is ignored and the pins are read as ? 0 ?. timer1 also has an internal ?reset input?. this reset can be generated by the ccp module ( section 15.0 ?capture/compare/pwm (ccp) modules? ). figure 12-1: timer1 block diagram figure 12-2: timer1 block diag ram: 16-bit read/write mode tmr1h tmr1l t1sync tmr1cs t1ckps1:t1ckps0 sleep input f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 tmr1if overflow tmr1 clr ccp special event trigger t1oscen enable oscillator (1) t1osc interrupt flag bit note 1: when enable bit t1oscen is cleared, the inverter and feedback resistor are turned off. this eliminates power drain. t1osi t13cki/t1oso t1osc t1sync tmr1cs t1ckps1:t1ckps0 sleep input t1oscen enable oscillator (1) tmr1if overflow interrupt f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 t13cki/t1oso t1osi tmr1 flag bit note 1: when enable bit t1oscen is cleared, the inverter and feedback re sistor are turned off. this eliminates power drain. data bus<7:0> 8 tmr1h 8 8 8 read tmr1l write tmr1l ccp special event trigger timer 1 tmr1l high byte clr
? 2004 microchip technology inc. ds30491c-page 161 pic18f6585/8585/6680/8680 12.2 timer1 oscillator a crystal oscillator circuit is built-in between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit, t1oscen (t1con<3>). the oscil- lator is a low-power oscillator rated up to 200 khz. it will continue to run during sleep. it is primarily intended for a 32 khz crystal. table 12-1 shows the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper start-up of the timer1 oscillator. 12.3 timer1 interrupt the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to 0ffffh and rolls over to 0000h. the tmr1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing tmr1 interrupt enable bit, tmr1ie (pie1<0>). 12.4 resetting timer1 using a ccp trigger output if the ccp module is configured in compare mode to generate a ?special event trigger? (ccp1m3:ccp1m0 = 1011 ), this signal will reset timer1 and start an a/d conversion (if the a/d module is enabled). timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger from ccp1, the write will take precedence. in this mode of operation, the ccpr1h:ccpr1l register pair effectively becomes the period register for timer1. 12.5 timer1 16-bit read/write mode timer1 can be configured for 16-bit reads and writes (see figure 12-2). when the rd16 control bit (t1con<7>) is set, the address for tmr1h is mapped to a buffer register for the high byte of timer1. a read from tmr1l will load the contents of the high byte of timer1 into the timer1 high byte buffer. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, is valid due to a rollover between reads. a write to the high byte of timer1 must also take place through the tmr1h buffer register. timer1 high byte is updated with the contents of tmr1h when a write occurs to tmr1l. this allows a user to write all 16 bits to both the high and low bytes of timer1 at once. the high byte of timer1 is not directly readable or writ- able in this mode. all reads and writes must take place through the timer1 high byte buffer register. writes to tmr1h do not clear the timer1 prescaler. the prescaler is only cleared on writes to tmr1l. table 12-2: registers associated with timer1 as a timer/counter table 12-1: capacitor selection for the alternate oscillator osc type freq c1 c2 lp 32 khz tbd (1) tbd (1) crystal to be tested: 32.768 khz epson c-001r32.768k-a 20 ppm note 1: microchip suggests 33 pf as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only. note: the special event triggers from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>). name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 0111 1111 0111 1111 tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu t1con rd16 ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0-00 0000 u-uu uuuu legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module.
pic18f6585/8585/6680/8680 ds30491c-page 162 ? 2004 microchip technology inc. 13.0 timer2 module the timer2 module timer has the following features:  8-bit timer (tmr2 register)  8-bit period register (pr2)  readable and writable (both registers)  software programmable prescaler (1:1, 1:4, 1:16)  software programmable postscaler (1:1 to 1:16)  interrupt on tmr2 match of pr2  ssp module optional use of tmr2 output to generate clock shift timer2 has a control register shown in register 13-1. timer2 can be shut-off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. figure 13-1 is a simplified block diagram of the timer2 module. register 13-1 shows the timer2 control regis- ter. the prescaler and postscaler selection of timer2 are controlled by this register. 13.1 timer2 operation timer2 can be used as the pwm time base for the pwm mode of the ccp module. the tmr2 register is readable and writable and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits, t2ckps1:t2ckps0 (t2con<1:0>). the match out- put of tmr2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr2 interrupt latched in flag bit, tmr2if (pir1<1>). the prescaler and postscaler counters are cleared when any of the following occurs:  a write to the tmr2 register  a write to the t2con register  any device reset (power-on reset, mclr reset, watchdog timer reset, or brown-out reset) tmr2 is not cleared when t2con is written. register 13-1: t2con: time r2 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-3 t2outps3:t2outps0 : timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale    1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps1:t2ckps0 : timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 163 pic18f6585/8585/6680/8680 13.2 timer2 interrupt the timer2 module has an 8-bit period register, pr2. timer2 increments from 00h until it matches pr2 and then resets to 00h on the next increment cycle. pr2 is a readable and writable register. the pr2 register is initialized to 0ffh upon reset. 13.3 output of tmr2 the output of tmr2 (before the postscaler) is fed to the synchronous serial port module which optionally uses it to generate the shift clock. figure 13-1: timer2 block diagram table 13-1: registers associated with timer2 as a timer/counter comparator tmr2 sets flag tmr2 output (1) reset postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if note 1: tmr2 register output can be software selected by the ssp module as a baud clock. t2outps3:t2outps0 t2ckps1:t2ckps0 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 tmr2 timer2 module register 0000 0000 0000 0000 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module.
pic18f6585/8585/6680/8680 ds30491c-page 164 ? 2004 microchip technology inc. 14.0 timer3 module the timer3 module timer/counter has the following features:  16-bit timer/counter (two 8-bit registers; tmr3h and tmr3l)  readable and writable (both registers)  internal or external clock select  interrupt on overflow from ffffh to 0000h  reset from ccp module trigger figure 14-1 is a simplified block diagram of the timer3 module. register 14-1 shows the timer3 control register. this register controls the operating mode of the timer3 module and sets the enhanced ccp1 and ccp2 clock source. register 12-1 shows the timer1 control register. this register controls the operating mode of the timer1 module, as well as containing the timer1 oscillator enable bit (t1oscen) which can be a clock source for timer3. register 14-1: t3con: time r3 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rd16 t3ccp2 t3ckps1 t3ckps0 t3ccp1 t3sync tmr3cs tmr3on bit 7 bit 0 bit 7 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer3 in one 16-bit operation 0 = enables register read/write of timer3 in two 8-bit operations bit 6, 3 t3ccp2:t3ccp1: timer3 and timer1 to ccpx enable bits 1x = timer3 is the clock source for compare/capture of ccp1 and ccp2 modules 01 = timer3 is the clock source for compare/capture of ccp2 module, timer1 is the clock source for compare/capture of ccp1 module 00 = timer1 is the clock source for compare/capture of ccp1 and ccp2 modules bit 5-4 t3ckps1:t3ckps0 : timer3 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 2 t3sync : timer3 external clock input synchronization control bit (not usable if the system clock comes from timer1/timer3.) when tmr3cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr3cs = 0 : this bit is ignored. timer3 uses the internal clock when tmr3cs = 0 . bit 1 tmr3cs: timer3 clock source select bit 1 = external clock input from timer1 oscillator or t13cki (on the rising edge after the first falling edge) 0 = internal clock (f osc /4) bit 0 tmr3on: timer3 on bit 1 = enables timer3 0 = stops timer3 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 165 pic18f6585/8585/6680/8680 14.1 timer3 operation timer3 can operate in one of these modes: as a timer  as a synchronous counter  as an asynchronous counter the operating mode is determined by the clock select bit, tmr3cs (t3con<1>). when tmr3cs = 0 , timer3 increments every instruc- tion cycle. when tmr3cs = 1 , timer3 increments on every rising edge of the timer1 external clock input or the timer1 oscillator if enabled. when the timer1 oscillator is enabled (t1oscen is set), the rc1/t1osi and rc0/t1oso/t13cki pins become inputs. that is, the trisc<1:0> value is ignored and the pins are read as ? 0 ?. timer3 also has an internal ?reset input?. this reset can be generated by the ccp module ( section 14.0 ?timer3 module? ). figure 14-1: timer3 block diagram figure 14-2: timer3 block diagram co nfigured in 16-bit read/write mode tmr3h tmr3l t1osc t3sync tmr3cs t3ckps1:t3ckps0 sleep input t1oscen enable oscillator (1) tmr3if overflow interrupt f osc /4 internal clock tmr3on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 t1oso/ t1osi flag bit (3) note 1: when enable bit t1oscen is cleared, the inverter and feedback resistor are turned off. th is eliminates power drain. t13cki clr ccp special trigger t3ccpx timer3 tmr3l t1osc t3sync tmr3cs t3ckps1:t3ckps0 sleep input t1oscen enable oscillator (1) f osc /4 internal clock tmr3on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 t1oso/ t1osi tmr3 t13cki clr ccp special trigger t3ccpx to timer1 clock input note 1: when the t1oscen bit is cleared, the inverter and feedback re sistor are turned off. th is eliminates power drain. high byte data bus<7:0> 8 tmr3h 8 8 8 read tmr3l write tmr3l set tmr3if flag bit on overflow
pic18f6585/8585/6680/8680 ds30491c-page 166 ? 2004 microchip technology inc. 14.2 timer1 oscillator the timer1 oscillator may be used as the clock source for timer3. the timer1 oscillator is enabled by setting the t1oscen (t1con<3>) bit. the oscillator is a low- power oscillator rated up to 200 khz. see section 12.0 ?timer1 module? for further details. 14.3 timer3 interrupt the tmr3 register pair (tmr3h:tmr3l) increments from 0000h to 0ffffh and rolls over to 0000h. the tmr3 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr3if (pir2<1>). this interrupt can be enabled/disabled by setting/clearing tmr3 interrupt enable bit, tmr3ie (pie2<1>). 14.4 resetting timer3 using a ccp trigger output if the ccp module is configured in compare mode to generate a ?special event trigger? (ccp1m3:ccp1m0 = 1011 ), this signal will reset timer3. timer3 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer3 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer3 coincides with a special event trigger from ccp1, the write will take precedence. in this mode of operation, the ccpr1h:ccpr1l register pair effectively becomes the period register for timer3. table 14-1: registers associated with timer3 as a timer/counter note: the special event triggers from the ccp module will not set interrupt flag bit, tmr3if (pir1<0>). name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/ gieh peie/ giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir2 ? cmif ? eeif bclif lvdif tmr3if ccp2if -0-0 0000 -0-0 0000 pie2 ? cmie ? eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 -0-0 0000 ipr2 ? cmip ? eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 -1-1 1111 tmr3l holding register for the least significant byte of the 16-bit tmr3 register xxxx xxxx uuuu uuuu tmr3h holding register for the most significant byte of the 16-bit tmr3 register xxxx xxxx uuuu uuuu t1con rd16 ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0-00 0000 u-uu uuuu t3con rd16 t3ccp2 t3ckps1 t3ckps0 t3ccp1 t3sync tmr3cs tmr3on 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer3 module.
? 2004 microchip technology inc. ds30491c-page 167 pic18f6585/8585/6680/8680 15.0 capture/compare/pwm (ccp) modules pic18fxx80/xx85 devices contain a total of two ccp modules: ccp1 and ccp2. ccp1 is an enhanced version of the ccp2 module. ccp1 is fully backward compatible with the ccp2 module. the ccp1 module differs from ccp2 in the following respect:  ccp1 contains a special trigger event that may reset timer1 or the timer3 register pair  ccp1 contains ?can message time-stamp trigger?  ccp1 contains enhanced pwm output with programmable dead band and auto-shutdown functionality additionally, the ccp2 special event trigger may be used to start an a/d conversion if the a/d module is enabled. to avoid duplicate information, this section describes basic ccp module operation that applies to both ccp1 and ccp2. enhanced ccp functionality of the ccp1 module is described in section 16.0 ?enhanced capture/compare/pwm (eccp) module? . the control registers for the ccp1 and ccp2 modules are shown in register 15-1 and register 15-2, respectively. table 15-2 details the interactions of the ccp and eccp modules. register 15-1: ccp1con register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 p1m1:p1m0: enhanced pwm output configuration bits if ccp1m<3:2> = 00 , 01 , 10 : xx =p1a assigned as capture/compare input; p1b, p1c, p1d assigned as port pins if ccp1m<3:2> = 11 : 00 = single output; p1a modulated; p1b, p1c, p1d assigned as port pins 01 = full-bridge output forward; p1d modulated; p1a active; p1b, p1c inactive 10 = half-bridge output; p1a, p1b modulated with dead-band control; p1c, p1d assigned as port pins 11 = full-bridge output reverse; p1b modulated; p1c active; p1a, p1d inactive bit 5-4 dc1b1:dc1b0 : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccpr1l. bit 3-0 ccp1m3:ccp1m0 : enhanced ccp mode select bits 0000 = capture/compare/pwm off (resets ccp1 module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = reserved 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, initialize ccp pin low, on compare match force ccp pin high 1001 = compare mode, initialize ccp pin high, on compare match force ccp pin low 1010 = compare mode, generate software interrupt only, ccp pin is unaffected 1011 = compare mode, trigger special event, resets tmr1 or tmr3 1100 = pwm mode; p1a, p1c active-high; p1b, p1d active-high 1101 = pwm mode; p1a, p1c active-high; p1b, p1d active-low 1110 = pwm mode; p1a, p1c active-low; p1b, p1d active-high 1111 = pwm mode; p1a, p1c active-low; p1b, p1d active-low legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 168 ? 2004 microchip technology inc. register 15-2: ccp2con register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dc2b1:dc2b0 : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccpr2l. bit 3-0 ccp2m3:ccp2m0 : ccp2 mode select bits 0000 = capture/compare/pwm off (resets ccp2 module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = reserved 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, initialize ccp pin low, on compare match force ccp pin high 1001 = compare mode, initialize ccp pin high, on compare match force ccp pin low 1010 = compare mode, generate software interrupt only, ccp pin is unaffected 1011 = compare mode, trigger special event, resets tmr1 or tmr3 and starts a/d conversion if a/d module is enabled 11xx = pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 169 pic18f6585/8585/6680/8680 15.1 ccp module both ccp1 and ccp2 are comprised of two 8-bit registers: ccprxl (low byte) and ccprxh (high byte), 1 x 2. the ccpxcon register controls the operation of ccpx. all are readable and writable. table 15-1 shows the timer resources of the ccp module modes. table 15-1: ccp mode ? timer resource 15.2 capture mode in capture mode, ccprxh:ccprxl captures the 16-bit value of the tmr1 or tmr3 register when an event occurs on pin ccpn. an event is defined as:  every falling edge  every rising edge  every 4th rising edge  every 16th rising edge an event is selected by control bits ccpxm3:ccpxm0 (ccpxcon<3:0>). when a capture is made, the inter- rupt request flag bit, ccpxif (pir registers), is set. it must be cleared in software. if another capture occurs before the value in register ccprx is read, the old captured value will be lost. 15.2.1 ccp pin configuration in capture mode, the ccpx pin should be configured as an input by setting the appropriate tris bit. 15.2.2 timer1/timer3 mode selection the timer used with each ccp module is selected in the t3ccp2:t3ccp1 bits of the t3con register. the timers used with the capture feature (either timer1 or timer3) must be running in timer mode or synchro- nized counter mode. in asynchronous counter mode, the capture operation may not work. table 15-2: interaction of ccp modules ccp mode timer resource capture compare pwm timer1 or timer3 timer1 or timer3 timer2 note: if the ccpx is configured as an output, a write to the port can cause a capture condition. ccp1 mode ccp2 mode interaction capture capture tmr1 or tmr3 time base. time base can be different for each ccp. capture compare the compare could be configured for the special event trigger which clears either tmr1 or tmr3 depending upon which time base is used. compare compare the compare(s) could be configured for the special event trigger which clears tmr1 or tmr3 depending upon which time base is used. pwm pwm the pwms will have the same frequency and update rate (tmr2 interrupt). pwm capture none. pwm compare none.
pic18f6585/8585/6680/8680 ds30491c-page 170 ? 2004 microchip technology inc. 15.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccpxie (pie registers) clear to avoid false interrupts and should clear the flag bit, ccpxif, following any such change in operating mode. 15.2.4 ccp prescaler there are four prescaler settings specified by bits ccpxm3:ccpxm0. whenever the ccpx module is turned off, or the ccpx module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. the prescaler counter will not be cleared; therefore, the first capture may be from a non-zero prescaler. example 15-1 shows the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. 15.2.5 can message time-stamp the can capture event occurs when a message is received in any of the receive buffers. when config- ured, the can module provides the trigger to the ccp1 module to cause a capture event. this feature is provided to time-stamp the received can messages. this feature is enabled by setting the cancap bit of the can i/o control register (ciocon<4>). the message receive signal from the can module then takes the place of the events on rc2/ccp1. example 15-1: changing between capture prescalers figure 15-1: capture mode operat ion block diagram clrf ccp1con ; turn ccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and ccp on movwf ccp1con ; load ccp1con with ; this value ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if tmr3 enable q?s ccp1con<3:0> ccp1 pin prescaler 1, 4, 16 and edge detect tmr3h tmr3l tmr1 enable t3ccp2 t3ccp2 ccpr2h ccpr2l tmr1h tmr1l set flag bit ccp2if tmr3 enable q?s ccp2con<3:0> ccp2 pin prescaler 1, 4, 16 and edge detect tmr3h tmr3l tmr1 enable t3ccp2 t3ccp1 t3ccp2 t3ccp1
? 2004 microchip technology inc. ds30491c-page 171 pic18f6585/8585/6680/8680 15.3 compare mode in compare mode, the 16-bit ccprx register value is constantly compared against either the tmr1 register pair value or the tmr3 register pair value. when a match occurs, the ccpx pin can have one of the following actions:  driven high driven low  toggle output (high-to-low or low-to-high)  remains unchanged the action on the pin is based on the value of control bits, ccpxm3:ccpxm0. at the same time, interrupt flag bit, ccpxif, is set. when configured to drive the ccp pin, the ccp1 pin cannot be changed; ccp1 module controls the pin. 15.3.1 ccp pin configuration the user must configure the ccpx pin as an output by clearing the appropriate tris bit. by default, the ccp2 pin is multiplexed with rc1. alternately, it can also be multiplexed with either rb3 or re7. this is done by changing the ccp2mx configuration bit. 15.3.2 timer1/timer3 mode selection the timer used with each ccp module is selected in the t3ccp2:t3ccp1 bits of the t3con register. timer1 and/or timer3 must be running in timer mode, or synchronized counter mode, if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 15.3.3 software interrupt mode when generate software interrupt is chosen, the ccpx pin is not affected. only a ccp interrupt is generated (if enabled). 15.3.4 special event trigger in this mode, an internal hardware trigger is generated which may be used to initiate an action. the special event trigger output of ccp1 resets either the tmr1 or tmr3 register pair. this allows the ccpr1 register to effectively be a 16-bit programmable period register for tmr1 or tmr3. additionally, the ccp2 special event trigger will start an a/d conversion if the a/d module is enabled. figure 15-2: compare mode operat ion block diagram note: clearing the ccpxcon register will force the ccpx compare output latch to the default low level. this is not the data latch. note: the special event trigger from the ccpx module will not set the timer1 or timer3 interrupt flag bits. ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic set flag bit ccp1if match rc2/ccp1 pin trisc<2> ccp1con<3:0> mode select output enable special event trigger will: reset timer1 or timer3, but not set timer1 or timer3 interrupt flag bit and set bit go/done (adcon0<2>) which starts an a/d conversion (ccp2 only) tmr3h tmr3l t3ccp2 ccpr2h ccpr2l comparator 1 0 t3ccp2 t3ccp1 qs r output logic special event trigger set flag bit ccp2if match rc1/ccp2 pin trisc<1> ccp2con<3:0> mode select output enable 01
pic18f6585/8585/6680/8680 ds30491c-page 172 ? 2004 microchip technology inc. table 15-3: registers associated with capture, compare, timer1 and timer3 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/ gieh peie/ giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 trisd portd data direction register 1111 1111 1111 1111 tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu t1con rd16 ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0-00 0000 u-uu uuuu ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 pir2 ? cmif ? eeif bclif lvdif tmr3if ccp2if -0-0 0000 -0-0 0000 pie2 ? cmie ? eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 -0-0 0000 ipr2 ? cmip ? eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 -1-1 1111 tmr3l holding register for the least significant byte of the 16-bit tmr3 register xxxx xxxx uuuu uuuu tmr3h holding register for the most significant byte of the 16-bit tmr3 register xxxx xxxx uuuu uuuu t3con rd16 t3ccp2 t3ckps1 t3ckps0 t3ccp1 t3sync tmr3cs tmr3on 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by capture and timer1.
? 2004 microchip technology inc. ds30491c-page 173 pic18f6585/8585/6680/8680 15.4 pwm mode in pulse width modulation (pwm) mode, the ccpx pin produces up to a 10-bit resolution pwm output. for pwm mode to function properly, the tris bit for the ccpx pin must be cleared to make it an output. figure 15-3 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 15.4.3 ?setup for pwm operation? . figure 15-3: simplified pwm block diagram a pwm output (figure 15-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 15-4: pwm output 15.4.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula. equation 15-1: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: tmr2 is cleared  the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is latched from ccpr1l into ccpr1h 15.4.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccprxl register and to the ccpxcon<5:4> bits. up to 10-bit resolution is available. the ccprxl contains the eight msbs and the ccpxcon<5:4> contain the two lsbs. this 10-bit value is represented by ccprxl:ccpxcon<5:4>. the following equation is used to calculate the pwm duty cycle in time. equation 15-2: ccprxl and ccpxcon<5:4> can be written to at any time but the duty cycle value is not latched into ccprxh until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccprxh is a read-only register. the ccprxh register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the ccprxh and 2-bit latch match tmr2, concatenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccpx pin is cleared. note: clearing the ccpxcon register will force the ccpx pwm output latch to the default low level. this is not the port data latch. ccprxl (master) ccprxh (slave) comparator tmr2 pr2 (note 1) r q s duty cycle registers ccpxcon<5:4> clear timer, set ccpx pin and latch d.c. tris bit ccpx note 1: 8-bit timer is concatenated with 2-bit internal q clock or 2 bits of the prescaler to create 10-bit time base. comparator period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 note: the timer2 postscaler (see section 13.0 ?timer2 module? ) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. pwm period = [(pr2) + 1]  4  t osc  (tmr2 prescale value) pwm duty cycle = (ccprxl:ccpxcon<5:4>)  t osc  (tmr2 prescale value)
pic18f6585/8585/6680/8680 ds30491c-page 174 ? 2004 microchip technology inc. the maximum pwm resolution (bits) for a given pwm frequency is given by the following equation. equation 15-3: 15.4.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccprxl register and ccpxcon<5:4> bits. 3. make the ccpx pin an output by clearing corresponding tris bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccpx module for pwm operation. table 15-4: example pwm frequencies and resolutions at 40 mhz table 15-5: registers associated with pwm and timer2 note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. f osc f pwm --------------- ?? ?? log 2 () log ----------------------------- b i t s = pwm resolution (max) pwm frequency 2.44 khz 9.76 khz 39.06 khz 156.3 khz 312.5 khz 416.6 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value 0ffh 0ffh 0ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 5.5 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 trisc portc data direction register 1111 1111 1111 1111 tmr2 timer2 module register 0000 0000 0000 0000 pr2 timer2 module period register 1111 1111 1111 1111 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 ccpr2l capture/compare/pwm register 2 (lsb) xxxx xxxx uuuu uuuu ccpr2h capture/compare/pwm register 2 (msb) xxxx xxxx uuuu uuuu ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by pwm and timer2.
? 2004 microchip technology inc. ds30491c-page 175 pic18f6585/8585/6680/8680 16.0 enhanced capture/ compare/pwm (eccp) module the ccp1 module is implemented as a standard ccp module with enhanced pwm capabilities. these capa- bilities allow for 2 or 4 output channels, user selectable polarity, dead-band control, and automatic shutdown and restart and are discussed in detail in section 16.2 ?enhanced pwm mode? . the control register for ccp1 is shown in register 16-1. in addition to the expanded functions of the ccp1con register, the ccp1 module has two additional registers associated with enhanced pwm operation and auto-shutdown features:  eccp1del  eccp1as register 16-1: ccp1con register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 p1m1:p1m0: enhanced pwm output configuration bits if ccp1m<3:2> = 00 , 01 , 10 : xx = p1a assigned as capture/compare input; p1b, p1c, p1d assigned as port pins if ccp1m<3:2> = 11 : 00 = single output; p1a modulated, p1b, p1c, p1d assigned as port pins 01 = full-bridge output forward; p1d modulated; p1a active; p1b, p1c inactive 10 = half-bridge output; p1a, p1b modulated with dead-band control; p1c, p1d assigned as port pins 11 = full-bridge output reverse; p1b modulated; p1c active; p1a, p1d inactive bit 5-4 dc1b1:dc1b0 : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccpr1l. bit 3-0 ccp1m3:ccp1m0 : enhanced ccp mode select bits 0000 = capture/compare/pwm off (resets ccp1 module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = capture mode, can message time-stamp 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, initialize ccp pin low, on compare match, force ccp pin high 1001 = compare mode, initialize ccp pin high, on compare match, force ccp pin low 1010 = compare mode, generate software interrupt only, ccp pin is unaffected 1011 = compare mode, trigger special event, resets tmr1 or tmr3 1100 = pwm mode; p1a, p1c active-high; p1b, p1d active-high 1101 = pwm mode; p1a, p1c active-high; p1b, p1d active-low 1110 = pwm mode; p1a, p1c active-low; p1b, p1d active-high 1111 = pwm mode; p1a, p1c active-low; p1b, p1d active-low legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 176 ? 2004 microchip technology inc. 16.1 eccp outputs the enhanced ccp module may have up to four outputs depending on the selected operating mode. these outputs, designated p1a through p1d, are multiplexed with i/o pins rc2, re6, re5 and rg4. the pin assignments are summarized in table 16-1. to configure i/o pins as pwm outputs, the proper pwm mode must be selected by setting the p1mx and ccp1mx bits (ccp1con<7:6> and <3:0>, respec- tively). the appropriate tris direction bits for the port pins must also be set as outputs. table 16-1: pin assignments for various eccp modes figure 16-1: compare mode operation block diagram eccp mode ccp1con configuration rc2 re6 re5 rg4 compatible ccp 00xx11xx ccp1 re6 re5 rg4 dual pwm 10xx11xx p1a p1b (2) re5 rg4 quad pwm x1xx11xx p1a p1b (2) p1c (2) p1d legend: x = don?t care. shaded cells indicate pin assignments not used by eccp in a given mode. note 1: tris register values must be configured appropriately. 2: on pic18f8x8x devices, these pins can be alternately multiplexed with rh7 or rh6 by changing the eccpmx configuration bit. ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic set flag bit ccp1if match rb3/ccp1/p1a pin trisb<3> ccp1con<3:0> mode select output enable special event trigger will: reset timer1 or timer3, but will not set timer1 or timer3 interrupt flag bit and set bit go/done (adcon0<2>) which starts an a/d conversion. tmr3h tmr3l t3ccp2 1 0
? 2004 microchip technology inc. ds30491c-page 177 pic18f6585/8585/6680/8680 16.2 enhanced pwm mode the enhanced pwm mode provides additional pwm output options for a broader range of control applica- tions. the module is a backward compatible version of the standard ccp module and offers up to four outputs, designated p1a through p1d. users are also able to select the polarity of the signal (either active-high or active-low). the module?s output mode and polarity are configured by setting the p1m1:p1m0 and ccp1m3:ccp1m0 bits of the ccp1con register (ccp1con<7:6> and ccp1con<3:0>, respectively). figure 16-2 shows a simplified block diagram of pwm operation. all control registers are double-buffered and are loaded at the beginning of a new pwm cycle (the period boundary when timer2 resets) in order to pre- vent glitches on any of the outputs. the exception is the pwm delay register, eccp1del, which is loaded at either the duty cycle boundary or the boundary period (whichever comes first). because of the buffering, the module waits until the assigned timer resets instead of starting immediately. this means that enhanced pwm waveforms do not exactly match the standard pwm waveforms, but are instead offset by one full instruction cycle (4 t osc ). as before, the user must manually configure the appropriate tris bits for output. 16.2.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following equation. equation 16-1: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle:  tmr2 is cleared  the ccp1 pin is set (if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is copied from ccpr1l into ccpr1h 16.2.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the pwm duty cycle is calculated by the following equation. equation 16-2: ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not copied into ccpr1h until a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm opera- tion. when the ccpr1h and 2-bit latch match tmr2, concatenated with an internal 2-bit q clock or two bits of the tmr2 prescaler, the ccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the following equation: equation 16-3: 16.2.3 pwm output configurations the p1m1:p1m0 bits in the ccp1con register allow one of four configurations:  single output  half-bridge output  full-bridge output, forward mode  full-bridge output, reverse mode the single output mode is the standard pwm mode discussed in section 16.2 ?enhanced pwm mode? . the half-bridge and full-bridge output modes are covered in detail in the sections that follow. the general relationship of the outputs in all configurations is summarized in figure 16-3. note: the timer2 postscaler (see section 13.0 ?timer2 module? ) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. pwm period = [(pr2) + 1]  4  t osc  (tmr2 prescale value) note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. pwm duty cycle = (ccpr1l:ccp1con<5:4>)  t osc  (tmr2 prescale value) pwm resolution (max) = f osc f pwm log log(2) bits
pic18f6585/8585/6680/8680 ds30491c-page 178 ? 2004 microchip technology inc. table 16-2: example pwm frequencies and resolutions at 40 mhz figure 16-2: simplified block diagram of the enhanced pwm module figure 16-3: pwm output relationships (active-high state) pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 6.58 ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (note 1) rq s duty cycle registers ccp1con<5:4> clear timer, set ccp1 pin and latch d.c. note 1: the 8-bit timer tmr2 register is concatenated with the 2-bit internal q clock or 2 bits of the prescaler to create the 10-bit t ime base. 2: alternate setting controlled by the eccpmx bit (pic18f8x8x devices only). trisc<2> rc2/ccp1/p1a trise<6> re6/ad14/p1b or rh7 (2) trise<5> trisg<4> rg4/p1d output controller p1m1<1:0> 2 ccp1m<3:0> 4 ccp1del ccp1/p1a p1b p1c p1d re5/ad13/p1c or rh6 (2) 0 period 00 10 01 11 signal pr2 + 1 ccp1con <7:6> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive duty cycle (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) note 1: dead-band delay is progr ammed using the eccp1del register ( section 16.2.6 ?programmable dead-band delay? ).
? 2004 microchip technology inc. ds30491c-page 179 pic18f6585/8585/6680/8680 figure 16-4: pwm output relationships (active-low state) 0 period 00 10 01 11 signal pr2 + 1 ccp1con <7:6> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive duty cycle (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) note 1: dead-band delay is programmed using the eccp1del register ( section 16.2.6 ?programmable dead-band delay? ). relationships:  period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value)  duty cycle = t osc * (ccpr1l<7:0>:ccp1con<5:4>) * (tmr2 prescale value)  delay = 4 * t osc * (pwm1con<6:0>)
pic18f6585/8585/6680/8680 ds30491c-page 180 ? 2004 microchip technology inc. 16.2.4 half-bridge mode in the half-bridge output mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the p1a pin while the complementary pwm output signal is output on the p1b pin (figure 16-5). this mode can be used for half-bridge applications, as shown in figure 16-6, or for full-bridge applications where four power switches are being modulated with two pwm signals. in half-bridge output mode, the programmable dead- band delay can be used to prevent shoot-through current in half-bridge power devices. the value of bits pdc6:pdc0 sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. see section 16.2.6 ?programmable dead-band delay? for more details of the dead-band delay operations. since the p1a and p1b outputs are multiplexed with the portc<2> and porte<6> data latches, the trisc<2> and trise<6> bits must be cleared to configure p1a and p1b as outputs. figure 16-5: half-bridge pwm output figure 16-6: examples of half-bri dge output mode applications period duty cycle td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pic18fxx80/xx85 p1a p1b fet driver fet driver v+ v- load + v - + v - fet driver fet driver v+ v- load fet driver fet driver pic18fxx80/xx85 p1a p1b standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
? 2004 microchip technology inc. ds30491c-page 181 pic18f6585/8585/6680/8680 16.2.5 full-bridge mode in full-bridge output mode, four pins are used as outputs; however, only two outputs are active at a time. in the forward mode, pin p1a is continuously active and pin p1d is modulated. in the reverse mode, pin pgc is continuously active and pin p1b is modulated. these are illustrated in figure 16-7. p1a, p1b, p1c and p1d outputs are multiplexed with the portc<2>, porte<6:5> and portg<4> data latches. the trisc<2>, trisc<6:5> and trisg<4> bits must be cleared to make the p1a, p1b, p1c and p1d pins outputs. figure 16-7: full-bridge pwm output period duty cycle p1a (2) p1b (2) p1c (2) p1d (2) forward mode (1) period duty cycle p1a (2) p1c (2) p1d (2) p1b (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. note 2: output signal is shown as active-high.
pic18f6585/8585/6680/8680 ds30491c-page 182 ? 2004 microchip technology inc. figure 16-8: example of full-bridge application 16.2.5.1 direction change in full-bridge mode in the full-bridge output mode, the p1m1 bit in the ccp1con register allows the user to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will assume the new direction on the next pwm cycle. just before the end of the current pwm period, the mod- ulated outputs (p1b and p1d) are placed in their inactive state while the unmodulated outputs (p1a and p1c) are switched to drive in the opposite direction. this occurs in a time interval of (4 t osc * (timer2 prescale value)) before the next pwm period begins. the timer2 prescaler will be either 1, 4 or 16, depending on the value of the t2ckps bit (t2con<1:0>). during the interval from the switch of the unmodulated outputs to the beginning of the next period, the modulated outputs (p1b and p1d) remain inactive. this relationship is shown in figure 16-9. note that in the full-bridge output mode, the ccp1 module does not provide any dead-band delay. in general, since only one output is modulated at all times, dead-band delay is not required. however, there is a situation where a dead-band delay might be required. this situation occurs when both of the following conditions are true: 1. the direction of the pwm output changes when the duty cycle of the output is at or near 100%. 2. the turn off time of the power switch, including the power device and driver circuit, is greater than the turn on time. figure 16-10 shows an example where the pwm direc- tion changes from forward to reverse at a near 100% duty cycle. at time t1, the output p1a and p1d become inactive while output p1c becomes active. in this example, since the turn off time of the power devices is longer than the turn on time, a shoot-through current may flow through power devices qc and qd (see figure 16-8) for the duration of ?t?. the same phenom- enon will occur to power devices qa and qb for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, one of the following requirements must be met: 1. reduce pwm for a pwm period before changing directions. 2. use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. pic18fxx80/xx85 p1a p1c fet driver fet driver v+ v- load fet driver fet driver p1b p1d qa qb qd qc
? 2004 microchip technology inc. ds30491c-page 183 pic18f6585/8585/6680/8680 figure 16-9: pwm direction change figure 16-10: pwm direction chang e at near 100% duty cycle dc period (1) signal note 1: the direction bit in the ccp1 control register (ccp 1con<7>) is written any time during the pwm cycle. 2: when changing directions, the p1a and p1c signals switch before the end of the current pwm cycle at inter- vals of 4 t osc , 16 t osc or 64 t osc , depending on the timer2 prescaler value. the modulated p1b and p1d signals are inactive at this time. period (note 2) p1a (active-high) p1b (active-high) p1c (active-high) p1d (active-high) dc forward period reverse period p1a t on t off t = t off ? t on p1b p1c p1d external switch d potential shoot-through current note 1: all signals are shown as active-high. 2: t on is the turn on delay of power switch qc and its driver. 3: t off is the turn off delay of power switch qd and its driver. external switch c t1 dc dc
pic18f6585/8585/6680/8680 ds30491c-page 184 ? 2004 microchip technology inc. 16.2.6 programmable dead-band delay in half-bridge applications where all power switches are modulated at the pwm frequency at all times, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period of time until one switch completely turns off. during this brief interval, a very high current (shoot- through current) may flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flow- ing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in the half-bridge output mode, a digitally pro- grammable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transition from the non-active state to the active state. see figure 16-5 for an illustration. the lower seven bits of the eccp1del register (register 16-2) set the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). 16.2.7 enhanced pwm auto-shutdown when the ccp1 is programmed for any of the enhanced pwm modes, the active output pins may be configured for auto-shutdown. auto-shutdown immedi- ately places the enhanced pwm output pins into a defined shutdown state when a shutdown event occurs. a shutdown event can be caused by either of the two comparator modules or a low level on the rb0 pin (or any combination of these three sources). the compar- ators may be used to monitor a voltage input propor- tional to a current being monitored in the bridge circuit. if the voltage exceeds a threshold, the comparator switches state and triggers a shutdown. alternatively, a low digital signal on the rb0 pin can also trigger a shutdown. the auto-shutdown feature can be disabled by not selecting any auto-shutdown sources. the auto-shutdown sources to be used are selected using the eccpas2:eccpas0 bits (bits <6:4> of the eccp1as register). when a shutdown occurs, the output pins are asyn- chronously placed in their shutdown states, specified by the pssac1:pssac0 and pssbd1:pssbd0 bits (eccp1as<3:0>). each pin pair (p1a/p1c and p1b/ p1d) may be set to drive high, drive low, or be tri-stated (not driving). the eccpase bit (eccp1as<7>) is also set to hold the enhanced pwm outputs in their shutdown states. the eccpase bit is set by hardware when a shutdown event occurs. if automatic restarts are not enabled, the eccpase bit is cleared by firmware when the cause of the shutdown clears. if automatic restarts are enabled, the eccpase bit is automatically cleared when the cause of the auto-shutdown has cleared. if the eccpase bit is set when a pwm period begins, the pwm outputs remain in their shutdown state for that entire pwm period. when the eccpase bit is cleared, the pwm outputs will return to normal operation at the beginning of the next pwm period. register 16-2: eccp1del: eccp1 delay register note: writing to the eccpase bit is disabled while a shutdown condition is active. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 bit 7 bit 0 bit 7 prsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpase must be cleared in software to restart the pwm bit 6-0 pdc<6:0>: pwm delay count bits number of f osc /4 (4 * t osc ) cycles between the scheduled time when a pwm signal should transition active and the actual time it transitions active. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 185 pic18f6585/8585/6680/8680 register 16-3: eccp1as: enhanced capture/compare/pwm auto-shutdown control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 bit 7 bit 0 bit 7 eccpase: eccp auto-shutdown event status bit 0 = eccp outputs are operating 1 = a shutdown event has occurred; eccp outputs are in shutdown state bit 6-4 eccpas<2:0>: eccp auto-shutdown source select bits 000 = auto-shutdown is disabled 001 = comparator 1 output 010 = comparator 2 output 011 = either comparator 1 or 2 100 =rb0 101 = rb0 or comparator 1 110 = rb0 or comparator 2 111 = rb0 or comparator 1 or comparator 2 bit 3-2 pssacn: pins a and c shutdown state control bits 00 = drive pins a and c to ? 0 ? 01 = drive pins a and c to ? 1 ? 1x = pins a and c tri-state bit 1-0 pssbdn: pins b and d shutdown state control bits 00 = drive pins b and d to ? 0 ? 01 = drive pins b and d to ? 1 ? 1x = pins b and d tri-state legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 186 ? 2004 microchip technology inc. 16.2.7.1 auto-shutdown and automatic restart the auto-shutdown feature can be configured to allow automatic restarts of the module following a shutdown event. this is enabled by setting the prsen bit of the eccp1del register (eccp1del<7>). in shutdown mode with prsen = 1 (figure 16-11), the eccpase bit will remain set for as long as the cause of the shutdown continues. when the shutdown condi- tion clears, the eccpase bit is cleared. if prsen = 0 (figure 16-12), once a shutdown condition occurs, the eccpase bit will remain set until it is cleared by firm- ware. once eccpase is cleared, the enhanced pwm will resume at the beginning of the next pwm period. independent of the prsen bit setting, if the auto- shutdown source is one of the comparators, the shut- down condition is a level. the eccpase bit cannot be cleared as long as the cause of the shutdown persists. the auto-shutdown mode can be forced by writing a ? 1 ? to the eccpase bit. 16.2.8 start-up considerations when the eccp module is used in the pwm mode, the application hardware must use the proper external pull- up and/or pull-down resistors on the pwm output pins. when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the exter- nal circuits must keep the power switch devices in the off state until the microcontroller drives the i/o pins with the proper signal levels or activates the pwm output(s). the ccp1m1:ccp1m0 bits (ccp1con<1:0>) allow the user to choose whether the pwm output signals are active-high or active-low for each pair of pwm output pins (p1a/p1c and p1b/p1d). the pwm output polarities must be selected before the pwm pins are configured as outputs. changing the polarity configura- tion while the pwm pins are configured as outputs is not recommended since it may result in damage to the application circuits. the p1a, p1b, p1c and p1d output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pins for output at the same time as the eccp module may cause damage to the applica- tion circuit. the eccp module must be enabled in the proper output mode and complete a full pwm cycle before configuring the pwm pins as outputs. the com- pletion of a full pwm cycle is indicated by the tmr2if bit being set as the second pwm period begins. figure 16-11: pwm auto-shutdown (prsen = 1 , auto-restart enabled) figure 16-12: pwm auto-shutdown (prsen = 0 , auto-restart disabled) note: writing to the eccpase bit is disabled while a shutdown condition is active. shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccpase cleared by firmware pwm period
? 2004 microchip technology inc. ds30491c-page 187 pic18f6585/8585/6680/8680 16.2.9 setup for pwm operation the following steps should be taken when configuring the eccp1 module for pwm operation: 1. configure the pwm pins, p1a and p1b (and p1c and p1d, if used), as inputs by setting the corresponding trisb bits. 2. set the pwm period by loading the pr2 register. 3. configure the eccp1 module for the desired pwm mode and configuration by loading the ccp1con register with the appropriate values:  select one of the available output configurations and direction with the p1m1:p1m0 bits.  select the polarities of the pwm output signals with the ccp1m3:ccp1m0 bits. 4. set the pwm duty cycle by loading the ccpr1l register and ccp1con<5:4> bits. 5. for half-bridge output mode, set the dead- band delay by loading eccp1del<6:0> with the appropriate value. 6. if auto-shutdown operation is required, load the eccpas register:  select the auto-shutdown sources using the eccpas<2:0> bits.  select the shutdown states of the pwm output pins using pssac1:pssac0 and pssbd1:pssbd0 bits.  set the eccpase bit (eccpas<7>).  configure the comparators using the cmcon register.  configure the comparator inputs as analog inputs. 7. if auto-restart operation is required, set the prsen bit (eccp1del<7>). 8. configure and start tmr2:  clear the tmr2 interrupt flag bit by clearing the tmr2if bit (pir1<1>).  set the tmr2 prescale value by loading the t2ckps bits (t2con<1:0>).  enable timer2 by setting the tmr2on bit (t2con<2>). 9. enable pwm outputs after a new pwm cycle has started:  wait until tmr2 overflows (tmr2if bit is set).  enable the ccp1/p1a, p1b, p1c and/or p1d pin outputs by clearing the respective trisb bits.  clear the eccpase bit (eccp1as<7>). 16.2.10 effects of a reset both power-on and subsequent resets will force all ports to input mode and the ccp registers to their reset states. this forces the enhanced ccp module to reset to a state compatible with the standard ccp module. table 16-3: registers associated with pwm and timer2 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 trisc portc data direction register 1111 1111 1111 1111 trise porte data direction register 1111 1111 1111 1111 trisg ? ? ? portg data direction register ---1 1111 ---1 1111 tmr2 timer2 module register 0000 0000 0000 0000 pr2 timer2 module period register 1111 1111 1111 1111 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 eccp1as eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 0000 0000 0000 0000 eccp1del prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by pwm and timer2.
pic18f6585/8585/6680/8680 ds30491c-page 188 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 189 pic18f6585/8585/6680/8680 17.0 master synchronous serial port (mssp) module 17.1 master ssp (mssp) module overview the master synchronous serial port (mssp) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, dis- play drivers, a/d converters, etc. the mssp module can operate in one of two modes:  serial peripheral interface (spi)  inter-integrated circuit (i 2 c) - full master mode - slave mode (with general address call) the i 2 c interface supports the following modes in hardware: master mode  multi-master mode  slave mode 17.2 control registers the mssp module has three associated registers. these include a status register (sspstat) and two control registers (sspcon1 and sspcon2). the use of these registers and their individual configuration bits differ significantly depending on whether the mssp module is operated in spi or i 2 c mode. additional details are provided under the individual sections. 17.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. all four modes of spi are supported. to accomplish communication, typically three pins are used:  serial data out (sdo) ? rc5/sdo  serial data in (sdi) ? rc4/sdi/sda  serial clock (sck) ? rc3/sck/scl additionally, a fourth pin may be used when in a slave mode of operation:  slave select (ss ) ? rf7/ss figure 17-1 shows the block diagram of the mssp module when operating in spi mode. figure 17-1: mssp block diagram (spi mode) ( ) read write internal data bus sspsr reg sspm3:sspm0 bit0 shift clock ss control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to tx/rx in sspsr tris bit 2 smp:cke rc5/sdo sspbuf reg rc4/sdi/sda rf7/ss rc3/sck/ scl
pic18f6585/8585/6680/8680 ds30491c-page 190 ? 2004 microchip technology inc. 17.3.1 registers the mssp module has four registers for spi mode operation. these are:  mssp control register 1 (sspcon1)  mssp status register (sspstat)  serial receive/transmit buffer register (sspbuf)  mssp shift register (sspsr) ? not directly accessible sspcon1 and sspstat are the control and status registers in spi mode operation. the sspcon1 regis- ter is readable and writable. the lower 6 bits of the sspstat are read-only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. in receive operations, sspsr and sspbuf together create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double- buffered. a write to sspbuf will write to both sspbuf and sspsr. register 17-1: sspstat: mssp status register (spi mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp: sample bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock edge select bit when ckp = 0 : 1 = data transmitted on rising edge of sck 0 = data transmitted on falling edge of sck when ckp = 1 : 1 = data transmitted on falling edge of sck 0 = data transmitted on rising edge of sck bit 5 d/a : data/address bit used in i 2 c mode only. bit 4 p: stop bit used in i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write bit information used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit (receive mode only) 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 191 pic18f6585/8585/6680/8680 register 17-2: sspcon1: mssp control register 1 (spi mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol: write collision detect bit (transmit mode only) 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit spi slave mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode.the user must read the sspbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow note: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register. bit 5 sspen: synchronous serial port enable bit 1 = enables serial port and configures sck, sdo, sdi, and ss as serial port pins 0 = disables serial port and configures these pins as i/o port pins note: when enabled, these pins must be properly configured as input or output. bit 4 ckp: clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm3:sspm0: synchronous serial port mode select bits 0101 = spi slave mode, clock = sck pin, ss pin control disabled, ss can be used as i/o pin 0100 = spi slave mode, clock = sck pin, ss pin control enabled 0011 = spi master mode, clock = tmr2 output/2 0010 = spi master mode, clock = f osc /64 0001 = spi master mode, clock = f osc /16 0000 = spi master mode, clock = f osc /4 note: bit combinations not specifically listed here are either reserved or implemented in i 2 c mode only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 192 ? 2004 microchip technology inc. 17.3.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspcon1<5:0> and sspstat<7:6>). these control bits allow the following to be specified:  master mode (sck is the clock output)  slave mode (sck is the clock input)  clock polarity (idle state of sck)  data input sample phase (middle or end of data output time)  clock edge (output data on rising/falling edge of sck)  clock rate (master mode only)  slave select mode (slave mode only) the mssp consists of a transmit/receive shift regis- ter (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr, until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspbuf register. then the buffer full detect bit, bf (sspstat<0>) and the interrupt flag bit, sspif, are set. this double-buffering of the received data (sspbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspbuf register during transmission/reception of data will be ignored and the write collision detect bit, wcol (sspcon1<7>), will be set. user software must clear the wcol bit so that it can be determined if the follow- ing write(s) to the sspbuf register completed successfully. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data to transfer is written to the sspbuf. buffer full bit, bf (sspstat<0>), indicates when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the mssp interrupt is used to determine when the transmission/reception has com- pleted. the sspbuf must be read and/or written. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 17-1 shows the loading of the sspbuf (sspsr) for data transmission. the sspsr is not directly readable or writable and can only be accessed by addressing the sspbuf register. additionally, the mssp status register (sspstat) indicates the various status conditions. example 17-1: loading the sspbuf (sspsr) register loop btfss sspstat, bf ;has data been received(transmit complete)? bra loop ;no movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
? 2004 microchip technology inc. ds30491c-page 193 pic18f6585/8585/6680/8680 17.3.3 enabling spi i/o to enable the serial port, ssp enable bit, sspen (sspcon1<5>), must be set. to reset or reconfigure spi mode, clear the sspen bit, reinitialize the sspcon registers and then set the sspen bit. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port func- tion, some must have their data direction bits (in the tris register) appropriately programmed as follows:  sdi is automatically controlled by the spi module  sdo must have trisc<5> bit cleared  sck (master mode) must have trisc<3> bit cleared  sck (slave mode) must have trisc<3> bit set ss must have trisf<7> bit set any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. 17.3.4 typical connection figure 17-2 shows a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sck signal. data is shifted out of both shift registers on their pro- grammed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission:  master sends data - slave sends dummy data  master sends data - slave sends data  master sends dummy data - slave sends data figure 17-2: spi master/slave connection serial input buffer (sspbuf) shift register (sspsr) msb lsb sdo sdi processor 1 sck spi master sspm3:sspm0 = 00xxb serial input buffer (sspbuf) shift register (sspsr) lsb msb sdi sdo processor 2 sck spi slave sspm3:sspm0 = 010xb serial clock
pic18f6585/8585/6680/8680 ds30491c-page 194 ? 2004 microchip technology inc. 17.3.5 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave (processor 2, figure 17-2) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi is only going to receive, the sdo output could be dis- abled (programmed as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately program- ming the ckp bit (sspcon1<4>). this then, would give waveforms for spi communication, as shown in figure 17-3, figure 17-5 and figure 17-6, where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user programmable to be one of the following: f osc /4 (or t cy ) f osc /16 (or 4  t cy ) f osc /64 (or 16  t cy )  timer2 output/2 this allows a maximum data rate (at 40 mhz) of 10.00 mbps. figure 17-3 shows the waveforms for master mode. when the cke bit is set, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit. the time when the sspbuf is loaded with the received data is shown. figure 17-3: spi mode waveform (master mode) sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 4 clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 0 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2
? 2004 microchip technology inc. ds30491c-page 195 pic18f6585/8585/6680/8680 17.3.6 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the sspif interrupt flag bit is set. while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device will wake-up from sleep. 17.3.7 slave select synchronization the ss pin allows a synchronous slave mode. the spi must be in slave mode with ss pin control enabled (sspcon1<3:0> = 04h). the pin must not be driven low for the ss pin to function as an input. the data latch must be high. when the ss pin is low, transmission and reception are enabled and the sdo pin is driven. when the ss pin goes high, the sdo pin is no longer driven even if in the middle of a transmitted byte and becomes a floating output. external pull-up/pull-down resistors may be desirable depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ss pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdo pin can be connected to the sdi pin. when the spi needs to operate as a receiver, the sdo pin can be configured as an input. this disables transmissions from the sdo. the sdi can always be left as an input (sdi function) since it cannot create a bus conflict. figure 17-4: slave synchronization waveform note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke set, then the ss pin control must be enabled. input sample sdi bit 7 sdo bit 7 bit 6 bit 7 sspif interrupt (smp = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf flag bit 0 bit 7 bit 0 next q4 cycle after q2 sck (ckp = 1 sck (ckp = 0 cke = 0 ) ss
pic18f6585/8585/6680/8680 ds30491c-page 196 ? 2004 microchip technology inc. figure 17-5: spi mode waveform (slave mode with cke = 0 ) figure 17-6: spi mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag optional next q4 cycle after q2 sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag not optional next q4 cycle after q2
? 2004 microchip technology inc. ds30491c-page 197 pic18f6585/8585/6680/8680 17.3.8 sleep operation in master mode, all module clocks are halted and the transmission/reception will remain in that state until the device wakes from sleep. after the device returns to normal mode, the module will continue to transmit/receive data. in slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in sleep mode and data to be shifted into the spi transmit/receive shift register. when all 8 bits have been received, the mssp interrupt flag bit will be set and if enabled, will wake the device from sleep. 17.3.9 effects of a reset a reset disables the mssp module and terminates the current transfer. 17.3.10 bus mode compatibility table 17-1 shows the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 17-1: spi bus modes there is also a smp bit which controls when the data is sampled. table 17-2: registers associated with spi operation standard spi mode terminology control bits state ckp cke 0, 0 0 1 0, 1 0 0 1, 0 1 1 1, 1 1 0 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 trisc portc data direction register 1111 1111 1111 1111 trisf trisf7 trisf6 trisf5 trisf4 trisf3 trisf2 trisf1 trisf0 1111 1111 uuuu uuuu sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 sspstat smp cke d/a p s r/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the mssp in spi mode.
pic18f6585/8585/6680/8680 ds30491c-page 198 ? 2004 microchip technology inc. 17.4 i 2 c mode the mssp module in i 2 c mode fully implements all master and slave functions (including general call sup- port) and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master func- tion). the mssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer:  serial clock (scl) ? rc3/sck/scl  serial data (sda) ? rc4/sdi/sda the user must configure these pins as inputs or outputs through the trisc<4:3> bits. figure 17-7: mssp block diagram (i 2 c mode) 17.4.1 registers the mssp module has six registers for i 2 c operation. these are:  mssp control register 1 (sspcon1)  mssp control register 2 (sspcon2)  mssp status register (sspstat)  serial receive/transmit buffer (sspbuf)  mssp shift register (sspsr) ? not directly accessible  mssp address register (sspadd) sspcon, sspcon2 and sspstat are the control and status registers in i 2 c mode operation. the sspcon and sspcon2 registers are readable and writable. the lower six bits of the sspstat are read- only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. sspadd register holds the slave device address when the ssp is configured in i 2 c slave mode. when the ssp is configured in master mode, the lower seven bits of sspadd act as the baud rate generator reload value. in receive operations, sspsr and sspbuf together create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double- buffered. a write to sspbuf will write to both sspbuf and sspsr. read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) rc3/sck/ rc4/ shift clock msb sdi/ lsb sda scl
? 2004 microchip technology inc. ds30491c-page 199 pic18f6585/8585/6680/8680 register 17-3: sspstat: mssp status register (i 2 c mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enable smbus specific inputs 0 = disable smbus specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last note: this bit is cleared on reset and when sspen is cleared. bit 3 s: start bit 1 = indicates that a start bit has been detected last 0 = start bit was not detected last note: this bit is cleared on reset and when sspen is cleared. bit 2 r/w : read/write bit information (i 2 c mode only) in slave mode: 1 = read 0 = write note: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. in master mode: 1 = transmit is in progress 0 = transmit is not in progress note: oring this bit with sen, rsen, pen, rcen or acken will indicate if the mssp is in idle mode. bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit in transmit mode: 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty in receive mode: 1 = data transmit in progress (does not include the ack and stop bits), sspbuf is full 0 = data transmit complete (does not include the ack and stop bits), sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 200 ? 2004 microchip technology inc. register 17-4: sspcon1: mssp control register 1 (i 2 c mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: synchronous serial port enable bit 1 = enables the serial port and configures the sda and scl pins as the serial port pins 0 = disables serial port and configures these pins as i/o port pins note: when enabled, the sda and scl pins must be properly configured as input or output. bit 4 ckp: sck release control bit in slave mode: 1 = release clock 0 = holds clock low (clock stretch), used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm3:sspm0: synchronous serial port mode select bits 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1000 = i 2 c master mode, clock = f osc /(4 * (sspadd + 1)) 0111 = i 2 c slave mode, 10-bit address 0110 = i 2 c slave mode, 7-bit address note: bit combinations not specifically listed here are either reserved or implemented in spi mode only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 201 pic18f6585/8585/6680/8680 register 17-5: sspcon2: mssp control register 2 (i 2 c mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt acken rcen pen rsen sen bit 7 bit 0 bit 7 gcen: general call enable bit (slave mode only) 1 = enable interrupt when a general call address (0000h) is received in the sspsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) 1 = not acknowledge 0 = acknowledge note: value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. bit 4 acken: acknowledge sequence enable bit (master receive mode only) 1 = initiate acknowledge sequence on sda and scl pins and transmit ackdt data bit. automatically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (master mode only) 1 = enables receive mode for i 2 c 0 = receive idle bit 2 pen: stop condition enable bit (master mode only) 1 = initiate stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen: repeated start condition enabled bit (master mode only) 1 = initiate repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen: start condition enabled/stretch enabled bit in master mode: 1 = initiate start condition on sda and scl pins. automatically cleared by hardware. 0 = start condition idle in slave mode: 1 = clock stretching is enabled for both slave transmit and slave receive (stretch enabled) 0 = clock stretching is disabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: for bits acken, rcen, pen, rsen, sen: if the i 2 c module is not in the idle mode, this bit may not be set (no spooling) and the sspbuf may not be written (or writes to the sspbuf are disabled).
pic18f6585/8585/6680/8680 ds30491c-page 202 ? 2004 microchip technology inc. 17.4.2 operation the mssp module functions are enabled by setting mssp enable bit, sspen (sspcon<5>). the sspcon1 register allows control of the i 2 c oper- ation. four mode selection bits (sspcon<3:0>) allow one of the following i 2 c modes to be selected: i 2 c master mode, clock = osc/4 (sspadd + 1) i 2 c slave mode (7-bit address) i 2 c slave mode (10-bit address) i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled i 2 c firmware controlled master mode, slave is idle selection of any i 2 c mode with the sspen bit set, forces the scl and sda pins to be open-drain, pro- vided these pins are programmed to inputs by setting the appropriate trisc bits. to ensure proper operation of the module, pull-up resistors must be provided externally to the scl and sda pins. 17.4.3 slave mode in slave mode, the scl and sda pins must be config- ured as inputs (trisc<4:3> set). the mssp module will override the input state with the output data when required (slave-transmitter). the i 2 c slave mode hardware will always generate an interrupt on an address match. through the mode select bits, the user can also choose to interrupt on start and stop bits when an address is matched or the data transfer after an address match is received, the hardware automati- cally will generate the acknowledge (ack ) pulse and load the sspbuf register with the received value currently in the sspsr register. any combination of the following conditions will cause the mssp module not to give this ack pulse:  the buffer full bit bf (sspstat<0>) was set before the transfer was received.  the overflow bit sspov (sspcon<6>) was set before the transfer was received. in this case, the sspsr register value is not loaded into the sspbuf but bit sspif (pir1<3>) is set. the bf bit is cleared by reading the sspbuf register while bit sspov is cleared through software. the scl clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, are shown in timing parameter #100 and parameter #101. 17.4.3.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8 bits are shifted into the sspsr register. all incom- ing bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is com- pared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match and the bf and sspov bits are clear, the following events occur: 1. the sspsr register value is loaded into the sspbuf register. 2. the buffer full bit bf is set. 3. an ack pulse is generated. 4. mssp interrupt flag bit, sspif (pir1<3>), is set (interrupt is generated, if enabled) on the falling edge of the ninth scl pulse. in 10-bit address mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspstat<2>) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 11110 a9 a8 0 ?, where ? a9 ? and ? a8 ? are the two msbs of the address. the sequence of events for 10-bit address is as follows, with steps 7 through 9 for the slave-transmitter: 1. receive first (high) byte of address (bits sspif, bf and bit ua (sspstat<1>) are set). 2. update the sspadd register with second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf, and ua are set). 5. update the sspadd register with the first (high) byte of address. if match releases scl line, this will clear bit ua. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif.
? 2004 microchip technology inc. ds30491c-page 203 pic18f6585/8585/6680/8680 17.4.3.2 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register and the sda line is held low (ack ). when the address byte overflow condition exists, then the no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit bf (sspstat<0>) is set or bit sspov (sspcon1<6>) is set. an mssp interrupt is generated for each data transfer byte. flag bit sspif (pir1<3>) must be cleared in soft- ware. the sspstat register is used to determine the status of the byte. if sen is enabled (sspcon2<0> = 1 ), rc3/sck/scl will be held low (clock stretch) following each data transfer. the clock must be released by setting bit ckp (sspcon<4>). see section 17.4.4 ?clock stretching? for more detail. 17.4.3.3 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit and pin rc3/sck/scl is held low, regardless of sen (see section 17.4.4 ?clock stretching? for more detail). by stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. the transmit data must be loaded into the sspbuf register which also loads the sspsr register. then pin rc3/ sck/scl should be enabled by setting bit ckp (sspcon1<4>). the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time (figure 17-9). the ack pulse from the master-receiver is latched on the rising edge of the ninth scl input pulse. if the sda line is high (not ack ), then the data transfer is com- plete. in this case, when the ack is latched by the slave, the slave logic is reset (resets sspstat regis- ter) and the slave monitors for another occurrence of the start bit. if the sda line was low (ack ), the next transmit data must be loaded into the sspbuf register. again, pin rc3/sck/scl must be enabled by setting bit ckp. an mssp interrupt is generated for each data transfer byte. the sspif bit must be cleared in software and the sspstat register is used to determine the status of the byte. the sspif bit is set on the falling edge of the ninth clock pulse.
pic18f6585/8585/6680/8680 ds30491c-page 204 ? 2004 microchip technology inc. figure 17-8: i 2 c slave mode timing with sen = 0 (reception, 7-bit address) sda scl sspif bf (sspstat<0>) sspov (sspcon<6>) s 1 2 34 56 7 8 91 234 5 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 (pir1<3>) ckp (ckp does not reset to ? 0 ? when sen = 0 )
? 2004 microchip technology inc. ds30491c-page 205 pic18f6585/8585/6680/8680 figure 17-9: i 2 c slave mode timing (transmission, 7-bit address) sda scl sspif (pir1<3>) bf (sspstat<0>) a6 a5 a4 a3 a2 a1 d6 d5 d4 d3 d2 d1 d0 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr data in sampled s ack transmitting data r/w = 1 ack receiving address a7 d7 9 1 d6 d5 d4 d3 d2 d1 d0 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr transmitting data d7 1 ckp p ack ckp is set in software ckp is set in software scl held low while cpu responds to sspif
pic18f6585/8585/6680/8680 ds30491c-page 206 ? 2004 microchip technology inc. figure 17-10: i 2 c slave mode timing with sen = 0 (reception, 10-bit address) sda scl sspif bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 (pir1<3>) cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon<6>) sspov is set because sspbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspadd has taken place
? 2004 microchip technology inc. ds30491c-page 207 pic18f6585/8585/6680/8680 figure 17-11: i 2 c slave mode timing (transmission, 10-bit address) sda scl sspif bf (sspstat<0>) s 1234 5 6789 1 2345 678 9 12 345 78 9 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 (pir1<3>) receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address. sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspbuf to clear bf flag sr cleared in software write of sspbuf initiates transmit cleared in software completion of clears bf flag ckp (sspcon<4>) ckp is set in software ckp is automatically cleared in hardware, holding scl low clock is held low until update of sspadd has taken place data transmission clock is held low until ckp is set to ? 1 ? bf flag is clear third address sequence at the end of the
pic18f6585/8585/6680/8680 ds30491c-page 208 ? 2004 microchip technology inc. 17.4.4 clock stretching both 7- and 10-bit slave modes implement automatic clock stretching during a transmit sequence. the sen bit (sspcon2<0>) allows clock stretching to be enabled during receives. setting sen will cause the scl pin to be held low at the end of each data receive sequence. 17.4.4.1 clock stretching for 7-bit slave receive mode (sen = 1 ) in 7-bit slave receive mode, on the falling edge of the ninth clock at the end of the ack sequence if the bf bit is set, the ckp bit in the sspcon1 register is automat- ically cleared, forcing the scl output to be held low. the ckp being cleared to ? 0 ? will assert the scl line low. the ckp bit must be set in the user?s isr before reception is allowed to continue. by holding the scl line low, the user has time to service the isr and read the contents of the sspbuf before the master device can initiate another receive sequence. this will prevent buffer overruns from occurring (see figure 17-13). 17.4.4.2 clock stretching for 10-bit slave receive mode (sen = 1 ) in 10-bit slave receive mode, during the address sequence, clock stretching automatically takes place but ckp is not cleared. during this time, if the ua bit is set after the ninth clock, clock stretching is initiated. the ua bit is set after receiving the upper byte of the 10-bit address and following the receive of the second byte of the 10-bit address with the r/w bit cleared to ? 0 ?. the release of the clock line occurs upon updating sspadd. clock stretching will occur on each data receive sequence as described in 7-bit mode. 17.4.4.3 clock stretching for 7-bit slave transmit mode 7-bit slave transmit mode implements clock stretching by clearing the ckp bit after the falling edge of the ninth clock, if the bf bit is clear. this occurs regardless of the state of the sen bit. the user?s isr must set the ckp bit before transmis- sion is allowed to continue. by holding the scl line low, the user has time to service the isr and load the con- tents of the sspbuf before the master device can initiate another transmit sequence (see figure 17-9). 17.4.4.4 clock stretching for 10-bit slave transmit mode in 10-bit slave transmit mode, clock stretching is controlled during the first two address sequences by the state of the ua bit, just as it is in 10-bit slave receive mode. the first two addresses are followed by a third address sequence which contains the high order bits of the 10-bit address and the r/w bit set to ? 1 ?. after the third address sequence is performed, the ua bit is not set, the module is now configured in transmit mode, and clock stretching is controlled by the bf flag as in 7-bit slave transmit mode (see figure 17-11). note 1: if the user reads the contents of the sspbuf before the falling edge of the ninth clock, thus clearing the bf bit, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit. the user should be careful to clear the bf bit in the isr before the next receive sequence in order to prevent an overflow condition. note: if the user polls the ua bit and clears it by updating the sspadd register before the falling edge of the ninth clock occurs and if the user hasn?t cleared the bf bit by read- ing the sspbuf register before that time, then the ckp bit will still not be asserted low. clock stretching on the basis of the state of the bf bit only occurs during a data sequence, not an address sequence. note 1: if the user loads the contents of sspbuf, setting the bf bit before the falling edge of the ninth clock, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit.
? 2004 microchip technology inc. ds30491c-page 209 pic18f6585/8585/6680/8680 17.4.4.5 clock synchronization and the ckp bit when the ckp bit is cleared, the scl output is forced to ? 0 ?. however, setting the ckp bit will not assert the scl output low until the scl output is already sampled low. therefore, the ckp bit will not assert the scl line until an external i 2 c master device has already asserted the scl line. the scl output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted scl. this ensures that a write to the ckp bit will not violate the minimum high time requirement for scl (see figure 17-12). figure 17-12: clock synchronization timing sda scl dx-1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspcon ckp master device deasserts clock master device asserts clock
pic18f6585/8585/6680/8680 ds30491c-page 210 ? 2004 microchip technology inc. figure 17-13: i 2 c slave mode timing with sen = 1 (reception, 7-bit address) sda scl sspif bf (sspstat<0>) sspov (sspcon<6>) s 1 234 567 89 1 2345 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 (pir1<3>) ckp ckp written to ? 1 ? in if bf is cleared prior to the falling edge of the 9th clock, ckp will not be reset to ? 0 ? and no clock stretching will occur software clock is held low until ckp is set to ? 1 ? clock is not held low because buffer full bit is clear prior to falling edge of 9th clock clock is not held low because ack = 1 bf is set after falling edge of the 9th clock, ckp is reset to ?0? and clock stretching occurs
? 2004 microchip technology inc. ds30491c-page 211 pic18f6585/8585/6680/8680 figure 17-14: i 2 c slave mode timing sen = 1 (reception, 10-bit address) sda scl sspif bf (sspstat<0>) s 1 2345678 9 12 345 6789 12345 78 9 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 d7d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 (pir1<3>) cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address after falling edge ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address after falling edge sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon<6>) ckp written to ? 1 ? note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. in software clock is held low until update of sspadd has taken place of ninth clock. of ninth clock sspov is set because sspbuf is still full. ack is not sent. dummy read of sspbuf to clear bf flag clock is held low until ckp is set to ? 1 ? clock is not held low because ack = 1
pic18f6585/8585/6680/8680 ds30491c-page 212 ? 2004 microchip technology inc. 17.4.5 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually determines which device will be the slave addressed by the master. the exception is the general call address which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all ? 0 ?s with r/w = 0 . the general call address is recognized when the gen- eral call enable bit (gcen) is enabled (sspcon2<7> is set). following a start bit detect, 8 bits are shifted into the sspsr and the address is compared against the sspadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspsr is transferred to the sspbuf, the bf flag bit is set (eighth bit) and on the falling edge of the ninth bit (ack bit), the sspif interrupt flag bit is set. when the interrupt is serviced, the source for the inter- rupt can be checked by reading the contents of the sspbuf. the value can be used to determine if the address was device specific or a general call address. in 10-bit mode, the sspadd is required to be updated for the second half of the address to match and the ua bit is set (sspstat<1>). if the general call address is sampled when the gcen bit is set while the slave is configured in 10-bit address mode, then the second half of the address is not necessary, the ua bit will not be set and the slave will begin receiving data after the acknowledge (figure 17-15). figure 17-15: slave mode general call address sequence (7 or 10-bit address mode) sda scl s sspif bf (sspstat<0>) sspov (sspcon1<6>) cleared in software sspbuf is read r/w = 0 ack general call address address is compared to general call address gcen (sspcon2<7>) receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack , set interrupt ? 0 ? ? 1 ?
? 2004 microchip technology inc. ds30491c-page 213 pic18f6585/8585/6680/8680 17.4.6 master mode master mode is enabled by setting and clearing the appropriate sspm bits in sspcon1 and by setting the sspen bit. in master mode, the scl and sda lines are manipulated by the mssp hardware. master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit is set or the bus is idle, with both the s and p bits clear. in firmware controlled master mode, user code conducts all i 2 c bus operations based on start and stop bit conditions. once master mode is enabled, the user has six options. 1. assert a start condition on sda and scl. 2. assert a repeated start condition on sda and scl. 3. write to the sspbuf register initiating transmission of data/address. 4. configure the i 2 c port to receive data. 5. generate an acknowledge condition at the end of a received byte of data. 6. generate a stop condition on sda and scl. the following events will cause ssp interrupt flag bit, sspif, to be set (ssp interrupt if enabled):  start condition  stop condition  data transfer byte transmitted/received  acknowledge transmit  repeated start figure 17-16: mssp block diagram (i 2 c master mode) note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspbuf register to initiate transmission before the start condi- tion is complete. in this case, the sspbuf will not be written to and the wcol bit will be set, indicating that a write to the sspbuf did not occur. read write sspsr start bit, stop bit, start bit detect sspbuf internal data bus set/reset s, p, wcol (sspstat) shift clock msb lsb sda acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv scl scl in bus collision sda in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspadd<6:0> baud set sspif, bclif reset ackstat, pen (sspcon2) rate generator sspm3:sspm0
pic18f6585/8585/6680/8680 ds30491c-page 214 ? 2004 microchip technology inc. 17.4.6.1 i 2 c master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sda while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted con- tains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ?. thus, the first byte transmitted is a 7-bit slave address followed by a ? 1 ? to indicate a receive bit. serial data is received via sda while scl outputs the serial clock. serial data is received 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator used for the spi mode operation is used to set the scl clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. see section 17.4.7 ?baud rate generator? for more detail. a typical transmit sequence would go as follows: 1. the user generates a start condition by setting the start enable bit, sen (sspcon2<0>). 2. sspif is set. the mssp module will wait the required start time before any other operation takes place. 3. the user loads the sspbuf with the slave address to transmit. 4. address is shifted out the sda pin until all 8 bits are transmitted. 5. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 6. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 7. the user loads the sspbuf with eight bits of data. 8. data is shifted out the sda pin until all 8 bits are transmitted. 9. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 10. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 11. the user generates a stop condition by setting the stop enable bit pen (sspcon2<2>). 12. interrupt is generated once the stop condition is complete.
? 2004 microchip technology inc. ds30491c-page 215 pic18f6585/8585/6680/8680 17.4.7 baud rate generator in i 2 c master mode, the baud rate generator (brg) reload value is placed in the lower 7 bits of the sspadd register (figure 17-17). when a write occurs to sspbuf, the baud rate generator will automatically begin counting. the brg counts down to ? 0 ? and stops until another reload has taken place. the brg count is decremented twice per instruction cycle (t cy ) on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ack ), the internal clock will automatically stop counting and the scl pin will remain in its last state. table 17-3 demonstrates clock rates based on instruction cycles and the brg value loaded into sspadd. figure 17-17: baud rate generator block diagram table 17-3: i 2 c clock rate w/brg sspm3:sspm0 brg down counter clko f osc /4 sspadd<6:0> sspm3:sspm0 scl reload control reload f cy f cy *2 brg value f scl (2 rollovers of brg) 10 mhz 20 mhz 19h 400 khz (1) 10 mhz 20 mhz 20h 312.5 khz 10 mhz 20 mhz 64h 100 khz 4 mhz 8 mhz 0ah 400 khz (1) 4 mhz 8 mhz 0dh 308 khz 4 mhz 8 mhz 28h 100 khz 1 mhz 2 mhz 03h 333 khz (1) 1 mhz 2 mhz 0ah 100 khz 1 mhz 2 mhz 00h 1 mhz (1) note 1: the i 2 c interface does not conform to the 400 khz i 2 c specification (which applies to rates greater than 100 khz) in all details but may be used with care where higher rates are required by the application.
pic18f6585/8585/6680/8680 ds30491c-page 216 ? 2004 microchip technology inc. 17.4.7.1 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, deasserts the scl pin (scl allowed to float high). when the scl pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the scl pin is actually sampled high. when the scl pin is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. this ensures that the scl high time will always be at least one brg rollover count in the event that the clock is held low by an external device (figure 17-18). figure 17-18: baud rate generator timing with clock arbitration sda scl scl deasserted but slave holds dx-1 dx brg scl is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value scl low (clock arbitration) scl allowed to transition high brg decrements on q2 and q4 cycles
? 2004 microchip technology inc. ds30491c-page 217 pic18f6585/8585/6680/8680 17.4.8 i 2 c master mode start condition timing to initiate a start condition, the user sets the start con- dition enable bit, sen (sspcon2<0>). if the sda and scl pins are sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and starts its count. if scl and sda are both sampled high when the baud rate generator times out (t brg ), the sda pin is driven low. the action of the sda being driven low while scl is high is the start condition and causes the s bit (sspstat<3>) to be set. following this, the baud rate generator is reloaded with the contents of sspadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit (sspcon2<0>) will be automatically cleared by hardware, the baud rate generator is suspended, leaving the sda line held low and the start condition is complete. 17.4.8.1 wcol status flag if the user writes the sspbuf when a start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 17-19: first start bit timing note: if at the beginning of the start condition, the sda and scl pins are already sam- pled low or if during the start condition, the scl line is sampled low before the sda line is driven low, a bus collision occurs, the bus collision interrupt flag, bclif, is set, the start condition is aborted and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspcon2 is disabled until the start condition is complete. sda scl s t brg 1st bit 2nd bit t brg sda = 1 , at completion of start bit, scl = 1 write to sspbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspstat<3>) and sets sspif bit
pic18f6585/8585/6680/8680 ds30491c-page 218 ? 2004 microchip technology inc. 17.4.9 i 2 c master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspcon2<1>) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the scl pin is asserted low. when the scl pin is sampled low, the baud rate generator is loaded with the contents of sspadd<5:0> and begins counting. the sda pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out, if sda is sampled high, the scl pin will be deasserted (brought high). when scl is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins count- ing. sda and scl must be sampled high for one t brg . this action is then followed by assertion of the sda pin (sda = 0 ) for one t brg while scl is high. following this, the rsen bit (sspcon2<1>) will be automatically cleared and the baud rate generator will not be reloaded, leaving the sda pin held low. as soon as a start condition is detected on the sda and scl pins, the s bit (sspstat<3>) will be set. the sspif bit will not be set until the baud rate generator has timed out. immediately following the sspif bit getting set, the user may write the sspbuf with the 7-bit address in 7-bit mode, or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode) or eight bits of data (7-bit mode). 17.4.9.1 wcol status flag if the user writes the sspbuf when a repeated start sequence is in progress, the wcol is set and the con- tents of the buffer are unchanged (the write doesn?t occur). figure 17-20: repeat start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if:  sda is sampled low when scl goes from low-to-high.  scl goes low before sda is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower 5 bits of sspcon2 is disabled until the repeated start condition is complete. sda scl sr = repeated start write to sspcon2 write to sspbuf occurs here falling edge of ninth clock, end of xmit at completion of start bit, hardware clears rsen bit 1st bit set s (sspstat<3>) t brg t brg sda = 1 , sda = 1 , scl (no change). scl = 1 occurs here. t brg t brg t brg and sets sspif
? 2004 microchip technology inc. ds30491c-page 219 pic18f6585/8585/6680/8680 17.4.10 i 2 c master mode transmission transmission of a data byte, a 7-bit address, or the other half of a 10-bit address is accomplished by simply writing a value to the sspbuf register. this action will set the buffer full flag bit, bf and allow the baud rate generator to begin counting and start the next trans- mission. each bit of address/data will be shifted out onto the sda pin after the falling edge of scl is asserted (see data hold time specification parameter #106). scl is held low for one baud rate generator rollover count (t brg ). data should be valid before scl is released high (see data setup time specification parameter #107). when the scl pin is released high, it is held that way for t brg . the data on the sda pin must remain stable for that duration and some hold time after the next falling edge of scl. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf flag is cleared and the master releases sda. this allows the slave device being addressed to respond with an ack bit during the ninth bit time if an address match occurred, or if data was received properly. the status of ack is written into the ackdt bit on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit, ackstat, is cleared. if not, the bit is set. after the ninth clock, the sspif bit is set and the master clock (baud rate generator) is suspended until the next data byte is loaded into the sspbuf, leaving scl low and sda unchanged (figure 17-21). after the write to the sspbuf, each bit of the address will be shifted out on the falling edge of scl until all seven address bits and the r/w bit are completed. on the falling edge of the eighth clock, the master will deassert the sda pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sda pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspcon2<6>). following the falling edge of the ninth clock transmission of the address, the sspif is set, the bf flag is cleared and the baud rate generator is turned off until another write to the sspbuf takes place, holding scl low and allowing sda to float. 17.4.10.1 bf status flag in transmit mode, the bf bit (sspstat<0>) is set when the cpu writes to sspbuf and is cleared when all 8 bits are shifted out. 17.4.10.2 wcol status flag if the user writes the sspbuf when a transmit is already in progress (i.e., sspsr is still shifting out a data byte), the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). wcol must be cleared in software. 17.4.10.3 ackstat status flag in transmit mode, the ackstat bit (sspcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0 ) and is set when the slave does not acknowl- edge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call) or when the slave has properly received its data. 17.4.11 i 2 c master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspcon2<3>). the baud rate generator begins counting and on each rollover, the state of the scl pin changes (high-to-low/ low-to-high) and data is shifted into the sspsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the contents of the sspsr are loaded into the sspbuf, the bf flag bit is set, the sspif flag bit is set and the baud rate generator is suspended from counting, holding scl low. the mssp is now in idle state awaiting the next command. when the buffer is read by the cpu, the bf flag bit is automatically cleared. the user can then send an acknowledge bit at the end of reception by setting the acknowledge sequence enable bit, acken (sspcon2<4>). 17.4.11.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspbuf from sspsr. it is cleared when the sspbuf register is read. 17.4.11.2 sspov status flag in receive operation, the sspov bit is set when 8 bits are received into the sspsr and the bf flag bit is already set from a previous reception. 17.4.11.3 wcol status flag if the user writes the sspbuf when a receive is already in progress (i.e., sspsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the mssp module must be in an idle state before the rcen bit is set or the rcen bit will be disregarded.
pic18f6585/8585/6680/8680 ds30491c-page 220 ? 2004 microchip technology inc. figure 17-21: i 2 c master mode waveform (transmission, 7 or 10-bit address) sda scl sspif bf (sspstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspbuf is written in software from ssp interrupt after start condition, sen cleared by hardware s sspbuf written with 7-bit address and r/w start transmit scl held low while cpu responds to sspif sen = 0 of 10-bit address write sspcon2<0> sen = 1 , start condition begins from slave clear ackstat bit sspcon2<6> ackstat in sspcon2 = 1 cleared in software sspbuf written pen cleared in software r/w
? 2004 microchip technology inc. ds30491c-page 221 pic18f6585/8585/6680/8680 figure 17-22: i 2 c master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspif bf ack is not sent write to sspcon2<0> (sen = 1 ), write to sspbuf occurs here, ack from slave master configured as a receiver by programming sspcon2<3> (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sda = 0 , scl = 1 while cpu (sspstat<0>) ack last bit is shifted into sspsr and contents are unloaded into sspbuf cleared in software cleared in software set sspif interrupt at end of receive set p bit (sspstat<4>) and sspif cleared in software ack from master set sspif at end set sspif interrupt at end of acknowledge sequence set sspif interrupt at end of acknow- ledge sequence of receive set acken, start acknowledge sequence, sspov is set because sspbuf is still full sda = ackdt = 1 rcen cleared automatically rcen = 1 , start next receive write to sspcon2<4> to start acknowledge sequence, sda = ackdt (sspcon2<5>) = 0 rcen cleared automatically responds to sspif acken begin start condition cleared in software sda = ackdt = 0
pic18f6585/8585/6680/8680 ds30491c-page 222 ? 2004 microchip technology inc. 17.4.12 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspcon2<4>). when this bit is set, the scl pin is pulled low and the contents of the acknowledge data bit are presented on the sda pin. if the user wishes to gen- erate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate generator then counts for one rollover period (t brg ) and the scl pin is deasserted (pulled high). when the scl pin is sampled high (clock arbitration), the baud rate generator counts for t brg . the scl pin is then pulled low. following this, the acken bit is automatically cleared, the baud rate generator is turned off and the mssp module then goes into idle mode (figure 17-23). 17.4.12.1 wcol status flag if the user writes the sspbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). 17.4.13 stop condition timing a stop bit is asserted on the sda pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspcon2<2>). at the end of a receive/ transmit, the scl line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sda line low. when the sda line is sampled low, the baud rate generator is reloaded and counts down to ? 0 ?. when the baud rate generator times out, the scl pin will be brought high and one t brg (baud rate generator rollover count) later, the sda pin will be deasserted. when the sda pin is sam- pled high while scl is high, the p bit (sspstat<4>) is set. a t brg later, the pen bit is cleared and the sspif bit is set (figure 17-24). 17.4.13.1 wcol status flag if the user writes the sspbuf when a stop sequence is in progress, then the wcol bit is set and the con- tents of the buffer are unchanged (the write doesn?t occur). figure 17-23: acknowledge sequence waveform figure 17-24: stop cond ition receive or transmit mode note: t brg = one baud rate generator period. sda scl set sspif at the end acknowledge sequence starts here, write to sspcon2 acken automatically cleared cleared in t brg t brg of receive ack 8 acken = 1 , ackdt = 0 d0 9 sspif software set sspif at the end of acknowledge sequence cleared in software scl sda sda asserted low before rising edge of clock write to sspcon2, set pen falling edge of scl = 1 for t brg , followed by sda = 1 for t brg 9th clock scl brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sda sampled high. p bit (sspstat<4>) is set. t brg to setup stop condition ack p t brg pen bit (sspcon2<2>) is cleared by hardware and the sspif bit is set
? 2004 microchip technology inc. ds30491c-page 223 pic18f6585/8585/6680/8680 17.4.14 sleep operation while in sleep mode, the i 2 c module can receive addresses or data and when an address match or com- plete byte transfer occurs, wake the processor from sleep (if the mssp interrupt is enabled). 17.4.15 effect of a reset a reset disables the mssp module and terminates the current transfer. 17.4.16 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit (sspstat<4>) is set or the bus is idle, with both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be moni- tored for arbitration to see if the signal level is the expected output level. this check is performed in hardware with the result placed in the bclif bit. the states where arbitration can be lost are:  address transfer  data transfer  a start condition  a repeated start condition  an acknowledge condition 17.4.17 multi -master communication, bus collision and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sda pin, arbitration takes place when the master outputs a ? 1 ? on sda by letting sda float high and another master asserts a ? 0 ?. when the scl pin floats high, data should be stable. if the expected data on sda is a ? 1 ? and the data sampled on the sda pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag, bclif and reset the i 2 c port to its idle state (figure 17-25). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sda and scl lines are deasserted and the sspbuf can be written to. when the user services the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop, or acknowledge condi- tion was in progress when the bus collision occurred, the condition is aborted, the sda and scl lines are deasserted, and the respective control bits in the sspcon2 register are cleared. when the user ser- vices the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sda and scl pins. if a stop condition occurs, the sspif bit will be set. a write to the sspbuf will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determi- nation of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspstat register or the bus is idle and the s and p bits are cleared. figure 17-25: bus collision timing for transmit and acknowledge sda scl bclif sda released sda line pulled low by another source sample sda. while scl is high, data doesn?t match what is driven bus collision has occurred. set bus collision interrupt (bclif) by the master. by master data changes while scl = 0
pic18f6585/8585/6680/8680 ds30491c-page 224 ? 2004 microchip technology inc. 17.4.17.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sda or scl are sampled low at the beginning of the start condition (figure 17-26). b) scl is sampled low before sda is asserted low (figure 17-27). during a start condition, both the sda and the scl pins are monitored. if the sda pin is already low or the scl pin is already low, then all of the following occur:  the start condition is aborted,  the bclif flag is set, and  the mssp module is reset to its idle state (figure 17-26). the start condition begins with the sda and scl pins deasserted. when the sda pin is sampled high, the baud rate generator is loaded from sspadd<6:0> and counts down to ? 0 ?. if the scl pin is sampled low while sda is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sda pin is sampled low during this count, the brg is reset and the sda line is asserted early (figure 17-28). if, however, a ? 1 ? is sampled on the sda pin, the sda pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to ? 0 ? and during this time, if the scl pins are sampled as ? 0 ?, a bus collision does not occur. at the end of the brg count, the scl pin is asserted low. figure 17-26: bus collision during start condition (sda only) note: the reason that bus collision is not a factor during a start condition is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sda before the other. this condition does not cause a bus collision because the two masters must be allowed to arbitrate the first address follow- ing the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sda scl sen sda sampled low before sda goes low before the sen bit is set. s bit and sspif set because ssp module reset into idle state. sen cleared automatically because of bus collision. s bit and sspif set because set sen, enable start condition if sda = 1 , scl = 1 sda = 0 , scl = 1 . bclif s sspif sda = 0 , scl = 1 . sspif and bclif are cleared in software sspif and bclif are cleared in software set bclif; start condition. set bclif;
? 2004 microchip technology inc. ds30491c-page 225 pic18f6585/8585/6680/8680 figure 17-27: bus collision d uring start condition (scl = 0 ) figure 17-28: brg reset due to sda arbitrat ion during start condition sda scl sen bus collision occurs. set bclif. scl = 0 before sda = 0 , set sen, enable start sequence if sda = 1 , scl = 1 t brg t brg sda = 0 , scl = 1 bclif s sspif interrupt cleared in software bus collision occurs. set bclif. scl = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sda scl sen set s set sen, enable start sequence if sda = 1 , scl = 1 less than t brg t brg sda = 0 , scl = 1 bclif s sspif s interrupts cleared in software set sspif sda = 0 , scl = 1 , sda pulled low by other master. reset brg and assert sda. scl pulled low after brg time-out set sspif ? 0 ?
pic18f6585/8585/6680/8680 ds30491c-page 226 ? 2004 microchip technology inc. 17.4.17.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sda when scl goes from low level to high level. b) scl goes low before sda is asserted low, indicating that another master is attempting to transmit a data ? 1 ?. when the user deasserts sda and the pin is allowed to float high, the brg is loaded with sspadd<6:0> and counts down to ? 0 ?. the scl pin is then deasserted and when sampled high, the sda pin is sampled. if sda is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ? 0 ?, see figure 17-29). if sda is sampled high, the brg is reloaded and begins counting. if sda goes from high to low before the brg times out, no bus collision occurs because no two masters can assert sda at exactly the same time. if scl goes from high to low before the brg times out and sda has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition (see figure 17-30). if, at the end of the brg time-out, both scl and sda are still high, the sda pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the scl pin, the scl pin is driven low and the repeated start condition is complete. figure 17-29: bus collision during a repeat ed start condition (case 1) figure 17-30: bus collision during repeat ed start condition (case 2) sda scl rsen bclif s sspif sample sda when scl goes high. if sda = 0 , set bclif and release sda and scl. cleared in software ? 0 ? ? 0 ? sda scl bclif rsen s sspif interrupt cleared in software scl goes low before sda, set bclif. release sda and scl. t brg t brg ? 0 ?
? 2004 microchip technology inc. ds30491c-page 227 pic18f6585/8585/6680/8680 17.4.17.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sda pin has been deasserted and allowed to float high, sda is sampled low after the brg has timed out. b) after the scl pin is deasserted, scl is sampled low before sda goes high. the stop condition begins with sda asserted low. when sda is sampled low, the scl pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspadd<6:0> and counts down to ? 0 ?. after the brg times out, sda is sampled. if sda is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data ? 0 ? (figure 17-31). if the scl pin is sampled low before sda is allowed to float high, a bus collision occurs. this is another case of another master attempting to drive a data ? 0 ? (figure 17-32). figure 17-31: bus collision during a stop condition (case 1) figure 17-32: bus collision during a stop condition (case 2) sda scl bclif pen p sspif t brg t brg t brg sda asserted low sda sampled low after t brg , set bclif ? 0 ? ? 0 ? sda scl bclif pen p sspif t brg t brg t brg assert sda scl goes low before sda goes high, set bclif ? 0 ? ? 0 ?
pic18f6585/8585/6680/8680 ds30491c-page 228 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 229 pic18f6585/8585/6680/8680 18.0 enhanced universal synchronous asynchronous receiver transmitter (usart) the universal synchronous asynchronous receiver transmitter (usart) module is one of the two serial i/o modules. (usart is also known as a serial communications interface or sci.) the usart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the enhanced usart module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on sync break reception and 12-bit break character transmit. these make it ideally suited for use in local interconnect network bus (lin bus) systems. the usart can be configured in the following modes:  asynchronous (full-duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission  synchronous ? master (half-duplex) with selectable clock polarity  synchronous ? slave (half-duplex) with selectable clock polarity in order to configure pins rc6/tx/ck and rc7/rx/dt as the universal synchronous asynchronous receiver transmitter:  spen (rcsta<7>) bit must be set (= 1 ),  trisc<6> bit must be set (= 1 ), and  trisc<7> bit must be set (= 1 ) . the operation of the enhanced usart module is controlled through three registers:  transmit status and control (txsta)  receive status and control (rcsta)  baud rate control (baudcon) these are detailed on the following pages in register 18-1, register 18-2 and register 18-3, respectively. note: the usart control will automatically reconfigure the pin from input to output as needed.
pic18f6585/8585/6680/8680 ds30491c-page 230 ? 2004 microchip technology inc. register 18-1: txsta: transmit status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync sendb brgh trmt tx9d bit 7 bit 0 bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit 1 = transmit enabled 0 = transmit disabled note: sren/cren overrides txen in sync mode. bit 4 sync: usart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data can be address/data bit or a parity bit. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 231 pic18f6585/8585/6680/8680 register 18-2: rcsta: receive status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 bit 7 spen: serial port enable bit 1 = serial port enabled (configures rx/dt and tx/ck pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care. synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 9-bit (rx9 = 0 ) : don?t care. bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcreg register and receiving next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data this can be an address/data bit or a parity bit and must be calculated by user firmware. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 232 ? 2004 microchip technology inc. register 18-3: baudcon: baud rat e control register u-0 r-1 u-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 ? rcidl ? sckp brg16 ? wue abden bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 rcidl : receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 unimplemented: read as ? 0 ? bit 4 sckp : synchronous clock polarity select bit asynchronous mode: unused in this mode. synchronous mode: 1 = idle state for clock (ck) is a high level 0 = idle state for clock (ck) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrgh and spbrg 0 = 8-bit baud rate generator ? spbrg only (compatible mode), spbrgh value ignored bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode: 1 = usart will continue to sample the rx pin ? interrupt generated on falling edge; bit cleared in hardware on following rising edge 0 = rx pin not monitored or rising edge detected synchronous mode: unused in this mode. bit 0 abden : auto-baud detect enable bit asynchronous mode: 1 = enable baud rate measurement on the next character ? requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement disabled or completed synchronous mode: unused in this mode. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 233 pic18f6585/8585/6680/8680 18.1 usart baud rate generator (brg) the brg is a dedicated 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the usart. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudcon<3>) selects 16-bit mode. the spbrgh:spbrg register pair controls the period of a free-running timer. in asynchronous mode, bits brgh (txsta<2>) and brg16 also control the baud rate. in synchronous mode, bit brgh is ignored. table 18-1 shows the formula for computation of the baud rate for different usart modes which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrgh:spbrg registers can be calculated using the formulas in table 18-1. from this, the error in baud rate can be determined. an example calculation is shown in example 18-1. typical baud rates and error values for the various asynchronous modes are shown in table 18-2. it may be advantageous to use the high baud rate (brgh = 1 ) or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrgh:spbrg registers causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 18.1.1 sampling the data on the rc7/rx/dt pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 18-1: baud rate formulas example 18-1: calculating baud rate error table 18-2: registers associated with baud rate generator configuration bits brg/usart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrgh:spbrg register pair name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x baudcon ? rcidl ? sckp brg16 ? wue abden -1-0 0-00 -1-0 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used by the brg. for a device with f osc of 16 mhz, desired baud rate of 9600, asynchronous mode, 8-bit brg: desired baud rate = f osc /(64 ([spbrgh:spbrg] + 1)) solving for spbrgh:spbrg: x=((f osc /desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate= 16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? de sired baud rate)/desired baud rate = (9615 ? 9600)/9600 = 0.16%
pic18f6585/8585/6680/8680 ds30491c-page 234 ? 2004 microchip technology inc. table 18-3: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2 ? ? ? 1.221 1.73 255 1.202 0.16 129 1201 -0.16 103 2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2403 -0.16 51 9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9615 -0.16 12 19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 ? ? ? 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 ? ? ? 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.16 207 300 -0.16 103 300 -0.16 51 1.2 1.202 0.16 51 1201 -0.16 25 1201 -0.16 12 2.4 2.404 0.16 25 2403 -0.16 12 ? ? ? 9.6 8.929 -6.99 6 ? ? ? ? ? ? 19.2 20.833 8.51 2 ? ? ? ? ? ? 57.6 62.500 8.51 0 ? ? ? ? ? ? 115.2 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2???????????? 2.4 ? ? ? ? ? ? 2.441 1.73 255 2403 -0.16 207 9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ?
? 2004 microchip technology inc. ds30491c-page 235 pic18f6585/8585/6680/8680 baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 300 -0.04 1665 1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1201 -0.16 415 2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2403 -0.16 207 9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.04 832 300 -0.16 415 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 300 -0.01 6665 1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1200 -0.04 1665 2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2400 -0.04 832 9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9615 -0.16 207 19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19230 -0.16 103 57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57142 0.79 34 115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117647 -2.12 16 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.01 3332 300 -0.04 1665 300 -0.04 832 1.2 1.200 0.04 832 1201 -0.16 415 1201 -0.16 207 2.4 2.404 0.16 415 2403 -0.16 207 2403 -0.16 103 9.6 9.615 0.16 103 9615 -0.16 51 9615 -0.16 25 19.2 19.231 0.16 51 19230 -0.16 25 19230 -0.16 12 57.6 58.824 2.12 16 55555 3.55 8 ? ? ? 115.2 111.111 -3.55 8 ? ? ? ? ? ? table 18-3: baud rates for asynchronous modes (continued)
pic18f6585/8585/6680/8680 ds30491c-page 236 ? 2004 microchip technology inc. 18.1.2 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence (figure 18-1) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rx signal, the rx signal is timing the brg. in abd mode, the internal baud rate generator is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the auto-baud detect must receive a byte with the value 55h (ascii ?u?, which is also the lin bus sync character) in order to calculate the proper bit rate. the measurement is taken over both a low and a high bit time in order to minimize any effects caused by asymmetry of the incoming signal. after a start bit, the spbrg begins counting up using the preselected clock source on the first rising edge of rx. after eight bits on the rx pin or the fifth rising edge, an accumulated value totalling the proper brg period is left in the spbrgh:spbrg registers. once the 5th edge is seen (should correspond to the stop bit), the abden bit is automatically cleared. while calibrating the baud rate period, the brg regis- ters are clocked at 1/8th the preconfigured clock rate. note that the brg clock will be configured by the brg16 and brgh bits. independent of the brg16 bit setting, both the spbrg and spbrgh will be used as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrgh register. refer to table 18-4 for counter clock rates to the brg. while the abd sequence takes place, the usart state machine is held in idle. the rcif interrupt is set once the fifth rising edge on rx is detected. the value in the rcreg needs to be read to clear the rcif interrupt. rcreg content should be discarded. table 18-4: brg counter clock rates figure 18-1: automatic baud rate calculation note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator fre- quency and usart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32 note: during the abd sequence, spbrg and spbrgh are both used as a 16-bit counter independent of brg16 setting. brg value rx pin abden bit rcif bit bit 0 bit 1 (interrupt) read rcreg brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 stop bit edge #5 001ch note 1: the abd sequence requires the usart module to be configured in asynchronous mode and wue = 0 . spbrg xxxxh 1ch spbrgh xxxxh 00h
? 2004 microchip technology inc. ds30491c-page 237 pic18f6585/8585/6680/8680 18.2 usart asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txsta<4>). in this mode, the usart uses standard non-return-to-zero (nrz) for- mat (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip dedicated 8-bit/16-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the usart transmits and receives the lsb first. the usart?s transmitter and receiver are functionally inde- pendent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate depending on the brgh and brg16 bits (txsta<2> and baudcon<3>). parity is not supported by the hardware but can be implemented in software and stored as the 9th data bit. asynchronous mode is available in all low-power modes; it is available in sleep mode only when auto- wake-up on sync break is enabled. when in pri_idle mode, no changes to the baud rate generator values are required; however, other low-power mode clocks may operate at another frequency than the primary clock. therefore, the baud rate generator values may need to be adjusted. when operating in asynchronous mode, the usart module consists of the following important elements:  baud rate generator  sampling circuit  asynchronous transmitter  asynchronous receiver  auto-wake-up on sync break character  12-bit break character transmit  auto-baud rate detection 18.2.1 usart asynchronous transmitter the usart transmitter block diagram is shown in figure 18-2. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit txif (pir1<4>) is set. this interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in software. flag bit txif is not cleared immediately upon loading the transmit buffer register, txreg. txif becomes valid in the second instruction cycle following the load instruction. polling txif immediately following a load of txreg will return invalid results. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. status bit trmt is a read- only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set transmit bit tx9. can be used as address/data bit. 5. enable the transmission by setting bit txen which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. note 1: the tsr register is not mapped in data memory so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. note: when brgh and brg16 bits are set, spbrgh:spbrg must be more than ? 1 ?.
pic18f6585/8585/6680/8680 ds30491c-page 238 ? 2004 microchip technology inc. figure 18-2: usart transmit block diagram figure 18-3: asynchronous transmission figure 18-4: asynchronous transmission (back to back) txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rc6/tx/ck pin pin buffer and control 8 ? ? ? spbrgh brg16 word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rc6/tx/ck txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy (pin) stop bit transmit shift reg. write to txreg brg output (shift clock) rc6/tx/ck txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy (pin) start bit
? 2004 microchip technology inc. ds30491c-page 239 pic18f6585/8585/6680/8680 table 18-5: registers associated with asynchronous transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x txreg usart transmit register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-1 0-00 -1-1 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission.
pic18f6585/8585/6680/8680 ds30491c-page 240 ? 2004 microchip technology inc. 18.2.2 usart asynchronous receiver the receiver block diagram is shown in figure 18-5. the data is received on the rc7/rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter oper- ates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit rcie. 4. if 9-bit reception is desired, set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit rcif will be set when reception is com- plete and an interrupt will be generated if enable bit rcie was set. 7. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 18.2.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate.. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcif bit will be set when reception is com- plete. the interrupt will be acknowledged if the rcie and gie bits are set. 8. read the rcsta register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcreg to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 18-5: usart receive block diagram note: when brgh and brg16 bits are set, spbrgh:spbrg must be more than ? 1 ?. x64 baud rate clk baud rate generator rc7/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? spbrg spbrgh brg16 or 4
? 2004 microchip technology inc. ds30491c-page 241 pic18f6585/8585/6680/8680 to set up an asynchronous transmission: 1. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh (see section 18.1 ?usart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set transmit bit tx9. can be used as address/data bit. 5. enable the transmission by setting bit txen which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-6: asynchronous reception table 18-6: registers associated with asynchronous reception start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word causin g the oerr (overrun) bit to be set. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x rcreg usart receive register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-1 0-00 -1-1 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception.
pic18f6585/8585/6680/8680 ds30491c-page 242 ? 2004 microchip technology inc. 18.2.4 auto-wake-up on sync break character during sleep mode, all clocks to the usart are suspended. because of this, the baud rate generator is inactive and a proper byte reception cannot be per- formed. the auto-wake-up feature allows the controller to wake-up due to activity on the rx/dt line while the usart is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudcon<1>). once set, the typical receive sequence on rx/dt is disabled and the usart remains in an idle state monitoring for a wake-up event independent of the cpu mode. a wake-up event con- sists of a high-to-low transition on the rx/dt line. (this coincides with the start of a sync break or a wake-up signal character for the lin protocol.) following a wake-up event, the module generates an rcif interrupt. the interrupt is generated synchro- nously to the q clocks in normal operating modes (figure 18-7) and asynchronously, if the device is in sleep mode (figure 18-8). the interrupt condition is cleared by reading the rcreg register. the wue bit is automatically cleared once a low-to- high transition is observed on the rx line following the wake-up event. at this point, the usart module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. 18.2.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rx/dt, information with any state changes before the stop bit may signal a false end-of-character and cause data or framing errors. to work properly, therefore, the initial char acter in the transmission must be all ? 0 ?s. this can be 00h (8 bytes) for standard rs-232 devices or 000h (12 bits) for lin bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., xt or hs mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the usart. 18.2.4.2 special considerations using the wue bit the timing of wue and rcif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the usart in an idle mode. the wake-up event causes a receive interrupt by setting the rcif bit. the wue bit is cleared after this when a rising edge is seen on rx/dt. the interrupt condition is then cleared by read- ing the rcreg register. ordinarily, the data in rcreg will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set) and the rcif flag is set should not be used as an indicator of the integrity of the data in rcreg. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 18-7: auto-wake-up bit (wue) timings during normal operation figure 18-8: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit rx/dt line rcif cleared due to user read of rcreg note: the usart remains in idle while the wue bit is set. auto-cleared bit set by user q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit rx/dt line rcif cleared due to user read of rcreg sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur while the stposc signal is still active. this sequence should not depend on the presence of q clocks. 2: the usart remains in idle while the wue bit is set. sleep ends auto-cleared note 1 bit set by user
? 2004 microchip technology inc. ds30491c-page 243 pic18f6585/8585/6680/8680 18.2.5 break character sequence the enhanced usart module has the capability of sending the special break character sequences that are required by the lin bus standard. the break char- acter transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break character is sent whenever the sendb and txen bits (txsta<3> and txsta<5>) are set while the transmit shift register is loaded with data. note that the value of data written to txreg will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin specification). note that the data value written to the txreg for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmis- sion. see figure 18-9 for the timing of the break character sequence. 18.2.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin bus master. 1. configure the usart for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txreg with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txreg to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txreg becomes empty, as indicated by the txif, the next data byte can be written to txreg. 18.2.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces the configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 18.2.4 ?auto-wake-up on sync break character? . by enabling this feature, the usart will sample the next two transitions on rx/dt, cause an rcif interrupt, and receive the next data byte followed by another interrupt. note that following a break character, the user will typ- ically want to enable the auto-baud rate detect feature. for both methods, the user can set the abd bit once the txif interrupt is observed. figure 18-9: send break character sequence write to txreg brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txif bit (transmit buffer reg. empty flag) tx (pin) trmt bit (transmit shift reg. empty flag) sendb (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
pic18f6585/8585/6680/8680 ds30491c-page 244 ? 2004 microchip technology inc. 18.3 usart synchronous master mode the synchronous master mode is entered by setting the csrc bit (txsta<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition, enable bit, spen (rcsta<7>), is set in order to configure the rc6/tx/ck and rc7/rx/dt i/o pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ck line. clock polarity is selected with the sckp bit (baudcon<5>); setting sckp sets the idle state on ck as high, while clearing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 18.3.1 usart synchronous master transmission the usart transmitter block diagram is shown in figure 18-2. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cycle ), the txreg is empty and interrupt bit txif (pir1<4>) is set. the interrupt can be enabled/disabled by setting/clearing enable bit, txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the sta- tus of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit so the user must poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-10: synchronous transmission bit 0 bit 1 bit 7 word 1 q1 q2 q3q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 rc7/rx/dt rc6/tx/ck write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrg = 0 , continuous transmission of two 8-bit words. pin pin rc6/tx/ck pin (sckp = 0 ) (sckp = 1 )
? 2004 microchip technology inc. ds30491c-page 245 pic18f6585/8585/6680/8680 figure 18-11: synchronous transmis sion (through txen) table 18-7: registers associated with synchronous master transmission rc7/rx/dt pin rc6/tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x txreg usart transmit register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-0 0-00 -1-0 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission.
pic18f6585/8585/6680/8680 ds30491c-page 246 ? 2004 microchip technology inc. 18.3.2 usart synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcsta<5>), or the continuous receive enable bit, cren (rcsta<4>). data is sampled on the rc7/rx/dt pin on the falling edge of the clock. if enable bit sren is set, only a single word is received. if enable bit cren is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, set enable bit rcie. 5. if 9-bit reception is desired, set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if the enable bit rcie was set. 8. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-12: synchronous reception (master mode, sren) table 18-8: registers associated with synchronous master reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x rcreg usart receive register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-0 0-00 -1-0 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception. cren bit rc7/rx/dt pin rc7/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brgh = 0 . rc7/tx/ck pin (sckp = 0 ) (sckp = 1 )
? 2004 microchip technology inc. ds30491c-page 247 pic18f6585/8585/6680/8680 18.4 usart synchronous slave mode synchronous slave mode is entered by clearing bit csrc (txsta<7>). this mode differs from the synchronous master mode in that the shift clock is sup- plied externally at the rc6/tx/ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 18.4.1 usart synchronous slave transmit the operation of the synchronous master and slave modes are identical except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 18-9: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x txreg usart transmit register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-1 0-00 -1-1 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission.
pic18f6585/8585/6680/8680 ds30491c-page 248 ? 2004 microchip technology inc. 18.4.2 usart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep or any idle mode and bit sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcreg register; if the rcie enable bit is set, the inter- rupt generated will wake the chip from low-power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit rcif will be set when reception is complete. an interrupt will be generated if enable bit rcie was set. 6. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 18-10: registers associated with synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x rcreg usart receive register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 baudcon ? rcidl ? sckp brg16 ? wue abden -1-0 0-00 -1-0 0-00 spbrgh baud rate generator register, high byte 0000 0000 0000 0000 spbrg baud rate generator register, low byte 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used fo r synchronous slave reception.
? 2004 microchip technology inc. ds30491c-page 249 pic18f6585/8585/6680/8680 19.0 10-bit analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has 12 inputs for the pic18f6x8x devices and 16 inputs for the pic18f8x8x devices. this module allows conver- sion of an analog input signal to a corresponding 10-bit digital number. a new feature for the a/d converter is the addition of pro- grammable acquisition time. this feature allows the user to select a new channel for conversion and to set the go/done bit immediately. when the go/done bit is set, the selected channel is sampled for the programmed acquisition time before a conversion is actually started. this removes the firmware overhead that may have been required to allow for an acquisition (sampling) period (see register 19-3 and section 19.4 ?selecting the a/d conversion clock? ). the module has five registers:  a/d result high register (adresh)  a/d result low register (adresl)  a/d control register 0 (adcon0)  a/d control register 1 (adcon1)  a/d control register 2 (adcon2) the adcon0 register, shown in register 19-1, controls the operation of the a/d module. the adcon1 register, shown in register 19-2, configures the functions of the port pins. the adcon2 register, shown in register 19-3, configures the a/d clock source, programmed acquisition time and justification. register 19-1: adcon0 register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-2 chs3:chs0: analog channel select bits 0000 = channel 0 (an0) 0001 = channel 1 (an1) 0010 = channel 2 (an2) 0011 = channel 3 (an3) 0100 = channel 4 (an4) 0101 = channel 5 (an5) 0110 = channel 6 (an6) 0111 = channel 7 (an7) 1000 = channel 8 (an8) 1001 = channel 9 (an9) 1010 = channel 10 (an10) 1011 = channel 11 (an11) 1100 = channel 12 (an12) (1) 1101 = channel 13 (an13) (1) 1110 = channel 14 (an14) (1) 1111 = channel 15 (an15) (1) bit 1 go/done : a/d conversion status bit when adon = 1 : 1 = a/d conversion in progress. this bit is automatically cleared when the a/d conversion is complete. 0 = a/d idle bit 0 adon: a/d on bit 1 = a/d converter module is enabled 0 = a/d converter module is disabled and consumes no current note 1: these channels are only available on pic18f8x8x devices . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 250 ? 2004 microchip technology inc. register 19-2: adcon1 register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-4 vcfg1:vcfg0: voltage reference configuration bits bit 3-0 pcfg3:pcfg0: a/d port configuration control bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: channels an15 through an12 are not available on the 68-pin devices. a/d v ref + a/d v ref - 00 a vdd a vss 01 external v ref +a vss 10 a vdd external v ref - 11 external v ref + external v ref - a = analog input d = digital i/o shaded cells = additional channels available on the pic18f8x8x devices an15 an14 an13 an12 an11 an10 an9 an8 an7 an6 an5 an4 an3 an2 an1 an0 0000 a a a aaaaaaaaaaaaa 0001 d d a aaaaaaaaaaaaa 0010 d d d aaaaaaaaaaaaa 0011 d d d daaaaaaaaaaaa 0100 d d d ddaaaaaaaaaaa 0101 d d d dddaaaaaaaaaa 0110 d d d ddddaaaaaaaaa 0111 d d d dddddaaaaaaaa 1000 d d d ddddddaaaaaaa 1001 d d d dddddddaaaaaa 1010 d d d ddddddddaaaaa 1011 d d d dddddddddaaaa 1100 d d d d d d ddddddda a a 1101 d d d d d d dddddddd a a 1110 d d d d d d dddddddd d a 1111 d d d d d d dddddddd dd
? 2004 microchip technology inc. ds30491c-page 251 pic18f6585/8585/6680/8680 register 19-3: adcon2 register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 bit 7 bit 0 bit 7 adfm: a/d result format select bit 1 = right justified 0 = left justified bit 6 unimplemented: read as ? 0 ? bit 5-3 acqt2:acqt0: a/d acquisition time select bits 000 = 0 t ad (1) 001 = 2 t ad 010 = 4 t ad 011 = 6 t ad 100 = 8 t ad 101 = 12 t ad 110 = 16 t ad 111 = 20 t ad bit 2-0 adcs2:adcs0: a/d conversion clock select bits 000 = f osc /2 001 = f osc /8 010 = f osc /32 011 = f rc (clock derived from a/d rc oscillator) (1) 100 = f osc /4 101 = f osc /16 110 = f osc /64 111 = f rc (clock derived from a/d rc oscillator) (1) note 1: if the a/d f rc clock source is selected, a delay of one t cy (instruction cycle) is added before the a/d clock starts. this allows the sleep instruction to be executed before starting a conversion. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 252 ? 2004 microchip technology inc. the analog reference voltage is software selectable to either the device?s positive and negative supply voltage (av dd and av ss ) or the voltage level on the ra3/an3/ v ref + and ra2/an2/v ref - pins. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to oper- ate in sleep, the a/d conversion clock must be derived from the a/d?s internal rc oscillator. the output of the sample and hold is the input into the converter which generates the result via successive approximation. a device reset forces all registers to their reset state. this forces the a/d module to be turned off and any conversion in progress is aborted. each port pin associated with the a/d converter can be configured as an analog input or as a digital i/o. the adresh and adresl registers contain the result of the a/d conversion. when the a/d conversion is com- plete, the result is loaded into the adresh/adresl registers, the go/done bit (adcon0 register) is cleared and a/d interrupt flag bit adif is set. the block diagram of the a/d module is shown in figure 19-1. figure 19-1: a/d block diagram (input voltage) v ain v ref + reference voltage v dd vcfg1:vcfg0 chs3:chs0 an7 an6 an5 an4 an3 an2 an1 an0 0111 0110 0101 0100 0011 0010 0001 0000 10-bit converter v ref - v ss a/d an15 (1) an14 (1) an13 (1) an12 (1) an11 an10 an9 an8 1111 1110 1101 1100 1011 1010 1001 1000 note 1: channels an15 through an12 are not available on the pic18f6x8x. 2: i/o pins have diode protection to v dd and v ss .
? 2004 microchip technology inc. ds30491c-page 253 pic18f6585/8585/6680/8680 the value in the adresh/adresl registers is not modified for a power-on reset. the adresh/ adresl registers will contain unknown data after a power-on reset. after the a/d module has been configured as desired, the selected channel must be acquired before the con- version is started. the analog input channels must have their corresponding tris bits selected as an input. to determine acquisition time, see section 19.1 ?a/d acquisition requirements? . after this acquisi- tion time has elapsed, the a/d conversion can be started. an acquisition time can be programmed to occur between setting the go/done bit and the actual start of the conversion. the following steps should be followed to do an a/d conversion: 1. configure the a/d module:  configure analog pins, voltage reference and digital i/o (adcon1)  select a/d input channel (adcon0)  select a/d acquisition time (adcon2)  select a/d conversion clock (adcon2)  turn on a/d module (adcon0) 2. configure a/d interrupt (if desired):  clear adif bit  set adie bit  set gie bit 3. wait the required acquisition time (if required). 4. start conversion:  set go/done bit (adcon0 register) 5. wait for a/d conversion to complete by either:  polling for the go/done bit to be cleared or  waiting for the a/d interrupt 6. read a/d result registers (adresh:adresl); clear bit adif if required. 7. for next conversion, go to step 1 or step 2 as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before next acquisition starts. figure 19-2: analog input model v ain c pin rs anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = 120 pf v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ? ) v dd 500 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions = sampling switch resistance r ss
pic18f6585/8585/6680/8680 ds30491c-page 254 ? 2004 microchip technology inc. 19.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 19-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ). the source impedance affects the offset voltage at the analog input (due to pin leakage current). the maximum recommended impedance for analog sources is 2.5 k ? . after the analog input channel is selected (changed), this acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 19-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. example 19-1 shows the calculation of the minimum required acquisition time, t acq . this calculation is based on the following application system assumptions: c hold = 120 pf rs = 2.5 k ? conversion error 1/2 lsb v dd =5v rss = 7 k ? temperature = 50 c (system max.) v hold = 0v @ time = 0 19.2 a/d v ref + and v ref - references if external voltage references are used instead of the internal av dd and av ss sources, the source impedance of the v ref + and v ref - voltage sources must be consid- ered. during acquisition, currents supplied by these sources are insignificant. however, during conversion, the a/d module sinks and sources current through the reference sources. the effect of this current, as specified in parameter a50, along with source impedance must be considered to meet specified a/d resolution. equation 19-1: acquisition time equation 19-2: a/d minimum charging time example 19-1: calculating the minimum required acquisition time note: when the conversion is started, the holding capacitor is disconnected from the input pin. note: when using external voltage references with the a/d converter, the source imped- ance of the external voltage references must be less than 20 ? to obtain the spec- ified a/d resolution. higher reference source impedances will increase both offset and gain errors. resistive voltage dividers will not provide a sufficiently low source impedance. to maintain the best possible performance in a/d conversions, external v ref inputs should be buffered with an operational amplifier or other low output impedance circuit. t acq = amplifier settling time + holding capacitor charging time + temperature coefficient =t amp + t c + t coff v hold = (v ref ? (v ref /2048))  (1 ? e (-tc/c hold (r ic + r ss + r s )) ) or t c = -(120 pf)(1 k ? + r ss + r s ) ln(1/2047) t acq =t amp + t c + t coff temperature coefficient is only required for temperatures > 25 c. t acq =2 s + t c + [(temp ? 25 c)(0.05 s/ c)] t c =-c hold (r ic + r ss + r s ) ln(1/2047) -120 pf (1 k ? + 7 k ? + 2.5 k ? ) ln(0.0004885) -120 pf (10.5 k ? ) ln(0.0004885) -1.26 s (-7.6241) 9.61 s t acq =2 s + 9.61 s + [(50 c ? 25 c)(0.05 s/ c)] 11.61 s + 1.25 s 12.86 s
? 2004 microchip technology inc. ds30491c-page 255 pic18f6585/8585/6680/8680 19.3 selecting and configuring automatic acquisition time the adcon2 register allows the user to select an acquisition time that occurs each time the go/done bit is set. when the go/done bit is set, sampling is stopped and a conversion begins. the user is responsible for ensur- ing the required acquisition time has passed between selecting the desired input channel and setting the go/done bit. this occurs when the acqt2:acqt0 bits (adcon2<5:3>) remain in their reset state (? 000 ?) and is compatible with devices that do not offer programmable acquisition times. if desired, the acqt bits can be set to select a pro- grammable acquisition time for the a/d module. when the go/done bit is set, the a/d module continues to sample the input for the selected acquisition time, then automatically begins a conversion. since the acquisi- tion time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the go/done bit. in either case, when the conversion is completed, the go/done bit is cleared, the adif flag is set, and the a/d begins sampling the currently selected channel again. if an acquisition time is programmed, there is nothing to indicate if the acquisition time has ended or if the conversion has begun. 19.4 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 11 t ad per 10-bit conversion. the source of the a/d conversion clock is software selectable. there are seven possible options for t ad : for correct a/d conversions, the a/d conversion clock (t ad ) must be as short as possible but greater than the minimum t ad (approximately 2 s, see parameter 130 for more information). table 19-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. 19.5 configuring analog port pins the adcon1, trisa, trisf and trish registers con- trol the operation of the a/d port pins. the port pins needed as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs3:chs0 bits and the tris bits. table 19-1: t ad vs. device operating frequencies 2 t osc 4 t osc 8 t osc 16 t osc 32 t osc 64 t osc  internal rc oscillator note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins config- ured as digital inputs will convert an analog input. analog levels on a digitally configured input will not affect the conversion accuracy. 2: analog levels on any pin defined as a dig- ital input may cause the input buffer to consume current out of the device?s specification limits. ad clock source (t ad ) maximum device frequency operation adcs2:adcs0 pic18fxx80/xx85 pic18lfxx80/xx85 2 t osc 000 1.25 mhz 666 khz 4 t osc 100 2.50 mhz 1.33 mhz 8 t osc 001 5.00 mhz 2.66 mhz 16 t osc 101 10.0 mhz 5.33 mhz 32 t osc 010 20.0 mhz 10.65 mhz 64 t osc 110 40.0 mhz 21.33 mhz rc (3) x11 1.00 mhz (1) 1.00 mhz (2) note 1: the rc source has a typical t ad time of 4 s. 2: the rc source has a typical t ad time of 6 s. 3: for device frequencies above 1 mhz, the device must be in sleep for the entire conversion or the a/d accuracy may be out of specification.
pic18f6585/8585/6680/8680 ds30491c-page 256 ? 2004 microchip technology inc. 19.6 a/d conversions figure 19-3 shows the operation of the a/d converter after the go bit has been set and the acqt2:acqt0 bits are cleared. a conversion is started after the follow- ing instruction to allow entry into sleep mode before the conversion begins. figure 19-4 shows the operation of the a/d converter after the go bit has been set, the acqt2:acqt0 bits are set to ? 010 ? and selecting a 4 t ad acquisition time before the conversion starts. clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. this means the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is completed or aborted, a 2t ad wait is required before the next acquisition can be started. after this wait, acquisition on the selected channel is automatically started. 19.7 use of the ccp2 trigger an a/d conversion can be started by the ?special event trigger? of the ccp2 module. this requires that the ccp2m3:ccp2m0 bits (ccp2con<3:0>) be pro- grammed as ? 1011 ? and that the a/d module is enabled (adon bit is set). when the trigger occurs, the go/done bit will be set, starting the a/d conversion and the timer1 (or timer3) counter will be reset to zero. timer1 (or timer3) is reset to automatically repeat the a/d acquisition period with minimal software overhead (moving adresh/adresl to the desired location). the appropriate analog input channel must be selected and the minimum acquisition done before the ?special event trigger? sets the go/done bit (starts a conversion). if the a/d module is not enabled (adon is cleared), the ?special event trigger? will be ignored by the a/d module but will still reset the timer1 (or timer3) counter. figure 19-3: a/d conversion t ad cycles (a cqt <2:0> = 000 , t acq = 0 ) figure 19-4: a/d conversion t ad cycles (a cqt <2:0> = 010 , t acq = 4 t ad ) note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 11 set go bit holding capacitor is disconnected from analog input (typically 100 ns) t ad 9 t ad 10 t cy - t ad next q4: adresh/adresl is loaded, go bit is cleared, adif bit is set, holding capacitor is connected to analog input. conversion starts b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 1 2 3 4 5 6 7 8 11 set go bit (holding capacitor is disconnected) 9 10 next q4: adresh:adresl is loaded, go bit is cleared, adif bit is set, holding capacitor is reconnected to analog input. conversion starts 1 2 3 4 (holding capacitor continues acquiring input) t acqt cycles t ad cycles automatic acquisition time b0 b9 b6 b5 b4 b3 b2 b1 b8 b7
? 2004 microchip technology inc. ds30491c-page 257 pic18f6585/8585/6680/8680 table 19-2: summary of a/d registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 1111 1111 pir2 ? cmif ?eeif bclif lvdif tmr3if ccp2if -0-0 0000 -0-0 0000 pie2 ? cmie ?eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 -0-0 0000 ipr2 ? cmip ?eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 -1-1 1111 adresh a/d result register high byte xxxx xxxx uuuu uuuu adresl a/d result register low byte xxxx xxxx uuuu uuuu adcon0 ? ? chs3 chs3 chs1 chs0 go/done adon --00 0000 --00 0000 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0000 --00 0000 adcon2 adfm ? ? ? ? adcs2 adcs1 adcs0 0--- -000 0--- -000 porta ? ra6 ra5 ra4 ra3 ra2 ra1 ra0 --xx xxxx --uu uuuu trisa ? porta data direction register --11 1111 --11 1111 portf rf7 rf6 rf5 rf4 rf3 rf2 rf1 rf0 xxxx xxxx uuuu uuuu latf latf7 latf6 latf5 latf4 latf3 latf2 latf1 latf0 xxxx xxxx uuuu uuuu trisf portf data direction control register 1111 1111 1111 1111 porth (1) rh7 rh6 rh5 rh4 rh3 rh2 rh1 rh0 xxxx xxxx uuuu uuuu lath (1) lath7 lath6 lath5 lath4 lath3 lath2 lath1 lath0 xxxx xxxx uuuu uuuu trish (1) porth data direction control register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used for a/d conversion. note 1: only available on pic18f8x8x devices.
pic18f6585/8585/6680/8680 ds30491c-page 258 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 259 pic18f6585/8585/6680/8680 20.0 comparator module the comparator module contains two analog comparators. the inputs to the comparators are multiplexed with the rf1 through rf6 pins. the on- chip voltage reference ( section 21.0 ?comparator voltage reference module? ) can also be an input to the comparators. the cmcon register, shown in register 20-1, controls the comparator input and output multiplexers. a block diagram of the various comparator configurations is shown in figure 20-1. register 20-1: cmcon register r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out : comparator 2 output bit when c2inv = 0 : 1 = c2 v in + > c2 v in - 0 = c2 v in + < c2 v in - when c2inv = 1 : 1 = c2 v in + < c2 v in - 0 = c2 v in + > c2 v in - bit 6 c1out : comparator 1 output bit when c1inv = 0 : 1 = c1 v in + > c1 v in - 0 = c1 v in + < c1 v in - when c1inv = 1 : 1 = c1 v in + < c1 v in - 0 = c1 v in + > c1 v in - bit 5 c2inv : comparator 2 output inversion bit 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv : comparator 1 output inversion bit 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis : comparator input switch bit when cm2:cm0 = 110 : 1 =c1 v in - connects to rf5/an10 c2 v in - connects to rf3/an8 0 =c1 v in - connects to rf6/an11 c2 v in - connects to rf4/an9 bit 2-0 cm2:cm0 : comparator mode bits figure 20-1 shows the comparator modes and cm2:cm0 bit settings. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 260 ? 2004 microchip technology inc. 20.1 comparator configuration there are eight modes of operation for the compara- tors. the cmcon register is used to select these modes. figure 20-1 shows the eight possible modes. the trisf register controls the data direction of the comparator pins for each mode. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in section 27.0 ?electrical characteristics? . figure 20-1: comparator i/o operating modes note: comparator interrupts should be disabled during a comparator mode change. otherwise, a false interrupt may occur. c1 rf6/an11 v in - v in + rf5/an10 off (read as ? 0 ?) comparators reset (por default value) a a cm2:cm0 = 000 c2 rf4/an9 v in - v in + rf3/an8 off (read as ? 0 ?) a a c1 rf6/an11 v in - v in + rf5/an10 c1out two independent comparators a a cm2:cm0 = 010 c2 rf4/an9 v in - v in + rf3/an8 c2out a a c1 rf6/an11 v in - v in + rf5/an10 c1out two common reference comparators a a cm2:cm0 = 100 c2 rf4/an9 v in - v in + rf3/an8 c2out a d c2 rf4/an9 v in - v in + rf3/an8 off (read as ? 0 ?) one independent comparator with output d d cm2:cm0 = 001 c1 rf6/an11 v in - v in + rf5/an10 c1out a a c1 rf6/an11 v in - v in + rf5/an10 off (read as ? 0 ?) comparators off d d cm2:cm0 = 111 c2 rf4/an9 v in - v in + rf3/an8 off (read as ? 0 ?) d d c1 rf6/an11 v in - v in + rf5/an10 c1out four inputs multiplexed to two comparators a a cm2:cm0 = 110 c2 rf4/an9 v in - v in + rf3/an8 c2out a a from v ref module cis = 0 cis = 1 cis = 0 cis = 1 c1 rf6/an11 v in - v in + rf5/an10 c1out two common reference comparators with outputs a a cm2:cm0 = 101 c2 rf4/an9 v in - v in + rf3/an8 c2out a d a = analog input, port reads zeros always d = digital input cis (cmcon<3>) = comparator input switch cv ref c1 rf6/an11 v in - v in + rf5/an10 c1out two independent comparators with outputs a a cm2:cm0 = 011 c2 rf4/an9 v in - v in + rf3/an8 c2out a a rf2/an7/c1out rf1/an6/c2out rf2/an7/c1out rf1/an6/c2out rf2/an7/c1out
? 2004 microchip technology inc. ds30491c-page 261 pic18f6585/8585/6680/8680 20.2 comparator operation a single comparator is shown in figure 20-2, along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 20-2 represent the uncertainty due to input offsets and response time. 20.3 comparator reference an external or internal reference signal may be used depending on the comparator operating mode. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly (figure 20-2). figure 20-2: single comparator 20.3.1 external reference signal when external voltage references are used, the comparator module can be configured to have the com- parators operate from the same or different reference sources. however, threshold detector applications may require the same reference. the reference signal must be between v ss and v dd and can be applied to either pin of the comparator(s). 20.3.2 internal reference signal the comparator module also allows the selection of an internally generated voltage reference for the compara- tors. section 21.0 ?comparator voltage reference module? contains a detailed description of the compar- ator voltage reference module that provides this signal. the internal reference signal is used when comparators are in mode cm<2:0> = 110 (figure 20-1). in this mode, the internal voltage reference is applied to the v in + pin of both comparators. 20.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. if the internal reference is changed, the maximum delay of the inter- nal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used ( section 27.0 ?electrical characteristics? ). 20.5 comparator outputs the comparator outputs are read through the cmcon register. these bits are read-only. the comparator outputs may also be directly output to the rf1 and rf2 i/o pins. when enabled, multiplexors in the output path of the rf1 and rf2 pins will switch and the output of each pin will be the unsynchronized output of the com- parator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 20-3 shows the comparator output block diagram. the trisa bits will still function as an output enable/disable for the rf1 and rf2 pins while in this mode. the polarity of the comparator outputs can be changed using the c2inv and c1inv bits (cmcon<4:5>). ? + v in + v in - output v in? v in+ o utput output v in + v in - note 1: when reading the port register, all pins configured as analog inputs will read as a ? 0 ?. pins configured as digital inputs will convert an analog input according to the schmitt trigger input specification. 2: analog levels on any pin defined as a dig- ital input may cause the input buffer to consume more current than is specified.
pic18f6585/8585/6680/8680 ds30491c-page 262 ? 2004 microchip technology inc. figure 20-3: comparator output block diagram 20.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:6>, to determine the actual change that occurred. the cmif bit (pir registers) is the comparator interrupt flag. the cmif bit must be reset by clearing it to ? 0 ?. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. the cmie bit (pie registers) and the peie bit (intcon register) must be set to enable the interrupt. in addition, the gie bit must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of cmcon will end the mismatch condition. b) clear flag bit cmif. a mismatch condition will continue to set flag bit cmif. reading cmcon will end the mismatch condition and allow flag bit cmif to be cleared. d q en to rf1 or rf2 pin bus data read cmcon set multiplex cmif bit - + d q en cl port pins read cmcon reset from other comparator cxinv note: if a change in the cmcon register (c1out or c2out) should occur when a read operation is being executed (start of the q2 cycle), then the cmif (pir registers) interrupt flag may not get set.
? 2004 microchip technology inc. ds30491c-page 263 pic18f6585/8585/6680/8680 20.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode when enabled. while the comparator is powered up, higher sleep currents than shown in the power-down current specification will occur. each operational comparator will consume additional current as shown in the com- parator specifications. to minimize power consumption while in sleep mode, turn off the comparators (cm<2:0> = 111 ) before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 20.8 effects of a reset a device reset forces the cmcon register to its reset state, causing the comparator module to be in the comparator reset mode (cm<2:0> = 000 ). this ensures that all potential inputs are analog inputs. device current is minimized when analog inputs are present at reset time. the comparators will be powered down during the reset interval. 20.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 20-4. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 20-4: comparator analog input model va r s < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 500 na v ss legend :c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input
pic18f6585/8585/6680/8680 ds30491c-page 264 ? 2004 microchip technology inc. table 20-1: registers associated with comparator module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 cvrcon cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 0000 0000 0000 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 0000 0000 0000 pir2 ?cmif ? eeif bclif lvdif tmr3if ccp2if -0-0 0000 -0-0 0000 pie2 ?cmie ? eeie bclie lvdie tmr3ie ccp2ie -0-0 0000 -0-0 0000 ipr2 ?cmip ? eeip bclip lvdip tmr3ip ccp2ip -1-1 1111 -1-1 1111 portf rf7 rf6 rf5 rf4 rf3 rf2 rf1 rf0 xxxx xxxx uuuu uuuu latf latf7 latf6 latf5 latf4 latf3 latf2 latf1 latf0 xxxx xxxx uuuu uuuu trisf trisf7 trisf6 trisf5 trisf4 trisf3 trisf2 trisf1 trisf0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are unused by the comparator module.
? 2004 microchip technology inc. ds30491c-page 265 pic18f6585/8585/6680/8680 21.0 comparator voltage reference module the comparator voltage reference is a 16-tap resistor ladder network that provides a selectable voltage reference. the resistor ladder is segmented to provide two ranges of cv ref values and has a power-down function to conserve power when the reference is not being used. the cvrcon register controls the operation of the reference as shown in register 21-1. the block diagram is given in figure 21-1. the comparator reference supply voltage can come from either v dd or v ss , or the external v ref + and v ref - that are multiplexed with ra3 and ra2. the comparator reference supply voltage is controlled by the cvrss bit. 21.1 configuring the comparator voltage reference the comparator voltage reference can output 16 distinct voltage levels for each range. the equations used to calculate the output of the comparator voltage reference are as follows: if cvrr = 1 : cv ref = (cvr<3:0>/24) x cv rsrc if cvrr = 0 : cv ref = (cv dd x 1/4) + (cvr<3:0>/32) x cv rsrc the settling time of the comparator voltage reference must be considered when changing the cv ref output ( section 27.0 ?electrical characteristics? ). register 21-1: cvrcon register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 bit 7 cvren : comparator voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 cvroe : comparator v ref output enable bit (1) 1 =cv ref voltage level is also output on the rf5/an10/c1in+/cv ref pin 0 =cv ref voltage is disconnected from the rf5/an10/c1in+/cv ref pin bit 5 cvrr : comparator v ref range selection bit 1 = 0.00 cv rsrc to 0.625 cv rsrc with cv rsrc /24 step size 0 = 0.25 cv rsrc to 0.71875 cv rsrc with cv rsrc /32 step size bit 4 cvrss : comparator v ref source selection bit 1 = comparator reference source, cv rsrc = v ref + ? v ref - 0 = comparator reference source, cv rsrc = v dd ? v ss note: to se l ec t ( v ref + ? v ref -) as the comparator voltage reference source, the voltage reference configuration bits in the adcon1 register (adcon1<5:4>) must also be set to ? 11 ?. bit 3-0 cvr3:cvr0: comparator v ref value selection bits (0 vr3:vr0 15) when cvrr = 1 : cv ref = (cvr<3:0>/24) ? (cv rsrc ) when cvrr = 0 : cv ref = 1/4 ? (cv rsrc ) + (cvr3:cvr0/32) ? (cv rsrc ) note 1: if enabled for output, rf5 must also be configured as an input by setting trisf<5> to ? 1 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 266 ? 2004 microchip technology inc. figure 21-1: voltage reference block diagram 21.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 21-1) keep cv ref from approaching the refer- ence source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the tested absolute accuracy of the voltage reference can be found in section 27.0 ?electrical characteristics? . 21.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 21.4 effects of a reset a device reset disables the voltage reference by clearing bit cvren (cvrcon<7>). this reset also disconnects the reference from the ra2 pin by clearing bit cvroe (cvrcon<6>) and selects the high- voltage range by clearing bit cvrr (cvrcon<5>). the vrss value select bits, cvrcon<3:0>, are also cleared. 21.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the rf5 pin if the trisf<5> bit is set and the cvroe bit is set. enabling the voltage reference output onto the rf5 pin with an input signal present will increase current consumption. connecting rf5 as a digital output with vrss enabled will also increase current consumption. the rf5 pin can be used as a simple d/a output with limited drive capability. due to the limited current drive capability, a buffer must be used on the voltage refer- ence output for external connections to v ref . figure 21-2 shows an example buffering technique. note: r is defined in section 27.0 ?electrical characteristics? . cvrr 8r cvr3 cvr0 (from cvrcon<3:0>) 16-1 analog mux 8r r r r r cvren cv ref 16 stages cvrss = 0 v dd v ref + cvrss = 0 cvrss = 1 v ref - cvrss = 1
? 2004 microchip technology inc. ds30491c-page 267 pic18f6585/8585/6680/8680 figure 21-2: voltage reference output buffer example table 21-1: registers associated with comparator voltage reference cv ref output + ? cv ref module voltage reference output impedance r (1) rf5 note 1: r is dependent upon the voltage reference confi guration bits cvrcon<3:0> and cvrcon<5>. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets cvrcon cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 0000 0000 0000 cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 trisf trisf7 trisf6 trisf5 trisf4 trisf3 trisf2 trisf1 trisf0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used with the comparator voltage reference.
pic18f6585/8585/6680/8680 ds30491c-page 268 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 269 pic18f6585/8585/6680/8680 22.0 low-voltage detect in many applications, the ability to determine if the device voltage (v dd ) is below a specified voltage level is a desirable feature. a window of operation for the application can be created where the application soft- ware can do ?housekeeping tasks? before the device voltage exits the valid operating range. this can be done using the low-voltage detect module. this module is a software programmable circuitry where a device voltage trip point can be specified. when the voltage of the device becomes lower then the specified point, an interrupt flag is set. if the interrupt is enabled, the program execution will branch to the inter- rupt vector address and the software can then respond to that interrupt source. the low-voltage detect circuitry is completely under software control. this allows the circuitry to be ?turned off? by the software which minimizes the current consumption for the device. figure 22-1 shows a possible application voltage curve (typically for batteries). over time, the device voltage decreases. when the device voltage equals voltage v a , the lvd logic generates an interrupt. this occurs at time t a . the application software then has the time, until the device voltage is no longer in valid operating range, to shut down the system. voltage point v b is the minimum valid operating voltage specification. this occurs at time t b . the difference, t b ? t a , is the total time for shutdown. figure 22-1: typical low-voltage detect application the block diagram for the lvd module is shown in figure 22-2. a comparator uses an internally gener- ated reference voltage as the set point. when the selected tap output of the device voltage crosses the set point (is lower than), the lvdif bit is set. each node in the resistor divider represents a ?trip point? voltage. the ?trip point? voltage is the minimum supply voltage level at which the device can operate before the lvd module asserts an interrupt. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the 1.2v internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal setting the lvdif bit. this voltage is software programmable to any one of 16 values (see figure 22-2). the trip point is selected by programming the lvdl3:lvdl0 bits (lvdcon<3:0>). time voltage v a v b t a t b v a = lvd trip point v b = minimum valid device operating voltage legend :
pic18f6585/8585/6680/8680 ds30491c-page 270 ? 2004 microchip technology inc. figure 22-2: low-voltage detect (lvd) block diagram the lvd module has an additional feature that allows the user to supply the trip voltage to the module from an external source. this mode is enabled when bits lvdl3:lvdl0 are set to ? 1111 ?. in this state, the com- parator input is multiplexed from the external input pin, lvdin (figure 22-3). this gives users flexibility because it allows them to configure the low-voltage detect interrupt to occur at any voltage in the valid operating range. figure 22-3: low-voltage detect (lvd) with external input block diagram lvdif v dd 16 to 1 mux lvden lvdcon internally generated reference voltage lvdin (parameter #d423) lvd3:lvd0 register lvd en 16 to 1 mux bgap boden lvden vxen lvdin v dd v dd externally generated trip point lvd3:lvd0 lvdcon register
? 2004 microchip technology inc. ds30491c-page 271 pic18f6585/8585/6680/8680 22.1 control register the low-voltage detect control register controls the operation of the low-voltage detect circuitry. register 22-1: lvdcon register u-0 u-0 r-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 ? ? irvst lvden lvdl3 lvdl2 lvdl1 lvdl0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the low-voltage detect logic will generate the interrupt flag at the specified voltage range 0 = indicates that the low-voltage detect logic will not generate the interrupt flag at the specified voltage range and the lvd interrupt should not be enabled bit 4 lvden: low-voltage detect power enable bit 1 = enables lvd, powers up lvd circuit 0 = disables lvd, powers down lvd circuit bit 3-0 lvdl3:lvdl0: low-voltage detection limit bits 1111 = external analog input is used (input comes from the lvdin pin) 1110 = 4.5v-4.77v 1101 = 4.2v-4.45v 1100 = 4.0v-4.24v 1011 = 3.8v-4.03v 1010 = 3.6v-3.82v 1001 = 3.5v-3.71v 1000 = 3.3v-3.50v 0111 = 3.0v-3.18v 0110 = 2.8v-2.97v 0101 = 2.7v-2.86v 0100 = 2.5v-2.65v 0011 = 2.4v-2.54v 0010 = 2.2v-2.33v 0001 = 2.0v-2.12v 0000 = reserved note: lvdl3:lvdl0 modes which result in a trip point below the valid operating voltage of the device are not tested. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 272 ? 2004 microchip technology inc. 22.2 operation depending on the power source for the device voltage, the voltage normally decreases relatively slowly. this means that the lvd module does not need to be constantly operating. to decrease the current require- ments, the lvd circuitry only needs to be enabled for short periods where the voltage is checked. after doing the check, the lvd module may be disabled. each time that the lvd module is enabled, the circuitry requires some time to stabilize. after the circuitry has stabilized, all status flags may be cleared. the module will then indicate the proper state of the system. the following steps are needed to set up the lvd module: 1. write the value to the lvdl3:lvdl0 bits (lvdcon register) which selects the desired lvd trip point. 2. ensure that lvd interrupts are disabled (the lvdie bit is cleared or the gie bit is cleared). 3. enable the lvd module (set the lvden bit in the lvdcon register). 4. wait for the lvd module to stabilize (the irvst bit to become set). 5. clear the lvd interrupt flag which may have falsely become set until the lvd module has stabilized (clear the lvdif bit). 6. enable the lvd interrupt (set the lvdie and the gie bits). figure 22-4 shows typical waveforms that the lvd module may be used to detect. figure 22-4: low-voltage detect waveforms v lvd v dd lvdif v lvd v dd enable lvd internally generated t ivrst lvdif may not be set enable lvd lvdif lvdif cleared in software lvdif cleared in software lvdif cleared in software, case 1: case 2: lvdif remains set since lvd condition still exists reference stable internally generated reference stable t ivrst
? 2004 microchip technology inc. ds30491c-page 273 pic18f6585/8585/6680/8680 22.2.1 reference voltage set point the internal reference voltage of the lvd module, specified in electrical specification parameter #d423, may be used by other internal circuitry (the program- mable brown-out reset). if these circuits are disabled (lower current consumption), the reference voltage circuit requires a time to become stable before a low- voltage condition can be reliably detected. this time is invariant of system clock speed. this start-up time is specified in electrical specification parameter #36. the low-voltage interrupt flag will not be enabled until a stable reference voltage is reached. refer to the waveform in figure 22-4. 22.2.2 current consumption when the module is enabled, the lvd comparator and voltage divider are enabled and will consume static cur- rent. the voltage divider can be tapped from multiple places in the resistor array. total current consumption, when enabled, is specified in electrical specification parameter #d022b. 22.3 operation during sleep when enabled, the lvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the lvdif bit will be set and the device will wake-up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 22.4 effects of a reset a device reset forces all registers to their reset state. this forces the lvd module to be turned off.
pic18f6585/8585/6680/8680 ds30491c-page 274 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 275 pic18f6585/8585/6680/8680 23.0 ecan module pic18f6585/8585/6680/8680 devices contain an enhanced controller area network (ecan) module. the ecan module is fully backward compatible with the can module available in pic18cxx8 and pic18fxx8 devices. the controller area network (can) module is a serial interface which is useful for communicating with other peripherals or microcontroller devices. this interface, or protocol, was designed to allow communications within noisy environments. the ecan module is a communication controller, implementing the can 2.0a or b protocol as defined in the bosch specification. the module will support can 1.2, can 2.0a, can 2.0b passive and can 2.0b active versions of the protocol. the module implemen- tation is a full can system; however, the can specifi- cation is not covered within this data sheet. refer to the bosch can specification for further details. the module features are as follows:  implementation of the can protocol can 1.2, can 2.0a and can 2.0b  devicenet tm data bytes filter support  standard and extended data frames  0-8 bytes data length  programmable bit rate up to 1 mbit/sec  fully backward compatible with pic18xx8 can module  three modes of operation: - mode 0 ? legacy mode - mode 1 ? enhanced legacy mode with devicenet support - mode 2 ? fifo mode with devicenet support  support for remote frames with automated handling  double-buffered receiver with two prioritized received message storage buffers  six buffers programmable as rx and tx message buffers  16 full (standard/extended identifier) acceptance filters that can be linked to one of four masks  two full acceptance filter masks that can be assigned to any filter  one full acceptance filter that can be used as either an acceptance filter or acceptance filter mask  three dedicated transmit buffers with application specified prioritization and abort capability  programmable wake-up functionality with integrated low-pass filter  programmable loopback mode supports self-test operation  signaling via interrupt capabilities for all can receiver and transmitter error states  programmable clock source  programmable link to timer module for time-stamping and network synchronization  low-power sleep mode 23.1 module overview the can bus module consists of a protocol engine and message buffering and control. the can protocol engine automatically handles all functions for receiving and transmitting messages on the can bus. messages are transmitted by first loading the appropriate data registers. status and errors can be checked by reading the appropriate registers. any message detected on the can bus is checked for errors and then matched against filters to see if it should be received and stored in one of the two receive registers. the can module supports the following frame types:  standard data frame  extended data frame  remote frame  error frame  overload frame reception  interframe space generation/detection the can module uses the rg0/cantx1, rg1/cantx2 and rg2/canrx pins to interface with the can bus. in normal mode, the can module automatically overrides the trisg0 and trisg1 bits of the can module pins. 23.1.1 module functionality the can bus module consists of a protocol engine, message buffering and control (see figure 23-1). the protocol engine can best be understood by defining the types of data frames to be transmitted and received by the module. the following sequence illustrates the necessary initial- ization steps before the ecan module can be used to transmit or receive a message. steps can be added or removed depending on the requirements of the application. 1. ensure that the ecan module is in configuration mode. 2. select ecan operational mode. 3. set up the baud rate registers. 4. set up the filter and mask registers. 5. set the ecan module to normal mode or any other mode required by the application logic.
pic18f6585/8585/6680/8680 ds30491c-page 276 ? 2004 microchip technology inc. figure 23-1: can buffers and protocol engine block diagram msgreq txb2 abtf mloa txerr mtxbuff message message queue control transmit byte sequencer msgreq txb1 abtf mloa txerr mtxbuff message msgreq txb0 abtf mloa txerr mtxbuff message acceptance filters (rxf0 ? rxf05) a c c e p t data field identifier acceptance mask rxm1 acceptance filters (rxf06 ? rxf15) m a b acceptance mask rxm0 rcv byte 16-4 to 1 muxs protocol message buffers transmit option mode 0 mode 1, 2 6 tx/rx buffers 2 rx buffers crc<14:0> comparator receive<8:0> transmit<7:0> receive error transmit error protocol rec tec err-pas bus-off finite state machine counter counter shift<14:0> {transmit<5:0>, receive<8:0>} transmit logic bit timing logic tx rx configuration registers clock generator buffers engine mode 0 mode 1, 2 rxf15 v cc
? 2004 microchip technology inc. ds30491c-page 277 pic18f6585/8585/6680/8680 23.2 can module registers there are many control and data registers associated with the can module. for convenience, their descriptions have been grouped into the following sections:  control and status registers  dedicated transmit buffer registers  dedicated receive buffer registers  programmable tx/rx and auto rtr buffers  baud rate control registers  i/o control register  interrupt status and control registers detailed descriptions of each register and their usage are described in the following sections. 23.2.1 can control and status registers the registers described in this section control the overall operation of the can module and show its operational status. note: not all can registers are available in the access bank.
pic18f6585/8585/6680/8680 ds30491c-page 278 ? 2004 microchip technology inc. register 23-1: cancon: can control regist er mode 0 r/w-1 r/w-0 r/w-0 r/s-0 r/w-0 r/w-0 r/w-0 u-0 reqop2 reqop1 reqop0 abat win2 win1 win0 ? mode 1 r/w-1 r/w-0 r/w-0 r/s-0 u-0 u-0 u-0 u-0 reqop2 reqop1 reqop0 abat ? ? ? ? mode 2 r/w-1 r/w-0 r/w-0 r/s-0 r-0 r-0 r-0 r-0 reqop2 reqop1 reqop0 abat fp3 fp2 fp1 fp0 bit 7 bit 0 bit 7-5 reqop2:reqop0: request can operation mode bits 1xx = request configuration mode 011 = request listen only mode 010 = request loopback mode 001 = request disable mode 000 = request normal mode bit 4 abat: abort all pending transmissions bit 1 = abort all pending transmissions (in all transmit buffers) 0 = transmissions proceeding as normal bit 3-1 mode 0: win2:win0: window address bits this selects which of the can buffers to switch into the access bank area. this allows access to the buffer registers from any data memory bank. after a frame has caused an interrupt, the icode2:icode0 bits can be copied to the win2:win0 bits to select the correct buffer. see example 23-2 for a code example. 111 = receive buffer 0 110 = receive buffer 0 101 = receive buffer 1 100 = transmit buffer 0 011 = transmit buffer 1 010 = transmit buffer 2 001 = receive buffer 0 000 = receive buffer 0 bit 0 unimplemented: read as ? 0 ? bit 3-0 mode 1: unimplemented: read as ? 0 ? mode 2: fp3:fp0: fifo read pointer bits these bits point to the message buffer to be read. 0111:0000 = message buffer to be read 1111:1000 = reserved legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 279 pic18f6585/8585/6680/8680 register 23-2: canstat: can status register mode 0 r-1 r-0 r-0 r-0 r-0 r-0 r-0 u-0 opmode2 (1) opmode1 (1) opmode0 (1) ? icode2 icode1 icode0 ? mode 1, 2 r-1 r-0 r-0 r-0 r-0 r-0 r-0 r-0 opmode2 (1) opmode1 (1) opmode0 (1) eicode4 eicode3 eicode2 eicode1 eicode0 bit 7 bit 0 bit 7-5 opmode2:opmode0: operation mode status bits (1) 111 = reserved 110 = reserved 101 = reserved 100 = configuration mode 011 = listen only mode 010 = loopback mode 001 = disable/sleep mode 000 = normal mode bit 4 mode 0: unimplemented: read as ? 0 ? bit 3-1 icode2:icode0 : interrupt code bits in mode 0 when an interrupt occurs, a prioritized coded interrupt value will be present in these bits. this code indicates the source of the interrupt. by copying icode2:icode0 to win2:win0, it is pos- sible to select the correct buffer to map into the access bank area. see example 23-2 for a code example. bit 0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown icode2:icode0 value no interrupt 000 error interrupt 001 txb2 interrupt 010 txb1 interrupt 011 txb0 interrupt 100 rxb1 interrupt 101 rxb0 interrupt 110 wake-up interrupt 111
pic18f6585/8585/6680/8680 ds30491c-page 280 ? 2004 microchip technology inc. register 23-2: canstat: can status register (continued) bit 4-0 mode 1,2: eicode4:eicode0 : interrupt code bits in mode 1 and mode 2 when an interrupt occurs, a prioritized coded interrupt value will be present in these bits. this code indicates the source of the interrupt. unlike icode bits in mode 0, these bits may not be copied directly to ewin bits to map interrupted buffer to access bank area. if required, user software may maintain a table in program memory to map eicode bits to ewin bits and access interrupt buffer in access bank area. note 1: to achieve maximum power saving and/or able to wake-up on can bus activity, switch can module to disable mode before putting the device to sleep. 2: in mode 2, if the buffer is configured as a receiver, eicode bits will always contain ? 10000 ? upon interrupt. legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared eicode4:eicode0 value no interrupt 00000 error interrupt 00010 txb2 interrupt 00100 txb1 interrupt 00110 txb0 interrupt 01000 rxb1 interrupt 10001/10000 (2) rxb0 interrupt 10000 wake-up interrupt 01110 rx/tx b0 interrupt 10010 (2) rx/tx b1 interrupt 10011 (2) rx/tx b2 interrupt 10100 (2) rx/tx b3 interrupt 10101 (2) rx/tx b4 interrupt 10110 (2) rx/tx b4 interrupt 10111 (2)
? 2004 microchip technology inc. ds30491c-page 281 pic18f6585/8585/6680/8680 example 23-1: changing to configuration mode example 23-2: win and icode bits usage in interrupt service routine to access tx/rx buffers ; request configuration mode. movlw b?10000000? ; set to configuration mode. movwf cancon ; a request to switch to configuration mode may not be immediately honored. ; module will wait for can bus to be idle before switching to configuration mode. ; request for other modes such as loopback, disable etc. may be honored immediately. ; it is always good practice to wait and verify before continuing. configwait: movf canstat, w ; read current mode state. andlw b?10000000? ; interested in opmode bits only. tstfsz wreg ; is it configuration mode yet? bra configwait ; no. continue to wait... ; module is in configuration mode now. ; modify configuration registers as required. ; switch back to normal mode to be able to communicate. ; save application required context. ; poll interrupt flags and determine source of interrupt ; this was found to be can interrupt ; tempcancon and tempcanstat are variables defined in access bank low movff cancon, tempcancon ; save cancon.win bits ; this is required to prevent cancon ; from corrupting can buffer access ; in-progress while this interrupt ; occurred movff canstat, tempcanstat ; save canstat register ; this is required to make sure that ; we use same canstat value rather ; than one changed by another can ; interrupt. movf tempcanstat, w ; retrieve icode bits andlw b?00001110? addwf pcl, f ; perform computed goto ; to corresponding interrupt cause bra nointerrupt ; 000 = no interrupt bra errorinterrupt ; 001 = error interrupt bra txb2interrupt ; 010 = txb2 interrupt bra txb1interrupt ; 011 = txb1 interrupt bra txb0interrupt ; 100 = txb0 interrupt bra rxb1interrupt ; 101 = rxb1 interrupt bra rxb0interrupt ; 110 = rxb0 interrupt ; 111 = wake-up on interrupt wakeupinterrupt bcf pir3, wakif ; clear the interrupt flag ; ; user code to handle wake-up procedure ; ; ; continue checking for other interrupt source or return from here ? nointerrupt ? ; pc should never vector here. user may ; place a trap such as infinite loop or pin/port ; indication to catch this error.
pic18f6585/8585/6680/8680 ds30491c-page 282 ? 2004 microchip technology inc. example 23-2: win and icode bits usage in interrupt service routine to access tx/rx buffers (continued) errorinterrupt bcf pir3, errif ; clear the interrupt flag ? ; handle error. retfie txb2interrupt bcf pir3, txb2if ; clear the interrupt flag goto accessbuffer txb1interrupt bcf pir3, txb1if ; clear the interrupt flag goto accessbuffer txb0interrupt bcf pir3, txb0if ; clear the interrupt flag goto accessbuffer rxb1interrupt bcf pir3, rxb1if ; clear the interrupt flag goto accessbuffer rxb0interrupt bcf pir3, rxb0if ; clear the interrupt flag goto accessbuffer accessbuffer ; this is either tx or rx interrupt ; copy canstat.icode bits to cancon.win bits movf tempcancon, w ; clear cancon.win bits before copying ; new ones. andlw b?11110001? ; use previously saved cancon value to ; make sure same value. movwf tempcancon ; copy masked value back to tempcancon movf tempcanstat, w ; retrieve icode bits andlw b?00001110? ; use previously saved canstat value ; to make sure same value. iorwf tempcancon ; copy icode bits to win bits. movff tempcancon, cancon ; copy the result to actual cancon ; access current buffer? ; user code ; restore cancon.win bits movf cancon, w ; preserve current non win bits andlw b?11110001? iorwf tempcancon ; restore original win bits ; do not need to restore canstat - it is read-only register. ; return from interrupt or check for another module interrupt source
? 2004 microchip technology inc. ds30491c-page 283 pic18f6585/8585/6680/8680 register 23-3: ecancon: enhanced can control register r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 mdsel1 (1, 2) mdsel0 (1, 2) fifowm ewin4 ewin3 ewin2 ewin1 ewin0 bit 7 bit 0 bit 7-6 mdsel1:mdsel0: mode select bits 00 = legacy mode (mode 0, default) 01 = enhanced legacy mode (mode 1) 10 = enhanced fifo mode (mode 2) 11 = reserved bit 5 fifowm: fifo high water mark bit (3) 1 = will cause fifo interrupt when one receive buffer remains (4) 0 = will cause fifo interrupt when four receive buffers remain bit 4-0 ewin4:ewin0: enhanced window address bits these bits map the group of 16 banked can sfrs into access bank addresses 0f60-0f6dh. exact group of registers to map is determined by binary value of these bits. mode 0: unimplemented: read as ? 0 ? mode 1, 2: 00000 = acceptance filters 0, 1, 2 and brgcon3, 2 00001 = acceptance filters 3, 4, 5 and brgcon1, ciocon 00010 = acceptance filter masks, error and interrupt control 00011 = transmit buffer 0 00100 = transmit buffer 1 00101 = transmit buffer 2 00110 = acceptance filters 6, 7, 8 00111 = acceptance filters 9, 10, 11 01000 = acceptance filters 12, 13, 14 01001 = acceptance filters 15 01010 - 01111 = reserved 10000 = receive buffer 0 10001 = receive buffer 1 10010 = tx/rx buffer 0 10011 = tx/rx buffer 1 10100 = tx/rx buffer 2 10101 = tx/rx buffer 3 10110 = tx/rx buffer 4 10111 = tx/rx buffer 5 11000 - 11111 = reserved note 1: these bits can only be changed in configuration mode. see register 19-2 to change to configuration mode. 2: a new mode takes into effect only after configuration mode is exited. 3: this bit is used in mode 2 only. 4: fifo length of 4 or less will cause this bit to be set. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 284 ? 2004 microchip technology inc. register 23-4: comstat: communication stat us register mode 0 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn mode 1 u-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 ? rxbnovfl txb0 txbp rxbp txwarn rxwarn ewarn mode 2 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 fifoempty rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn bit 7 bit 0 bit 7 mode 0: rxb0ovfl: receive buffer 0 overflow bit 1 = receive buffer 0 overflowed 0 = receive buffer 0 has not overflowed mode 1: unimplemented: read as ? 0 ? mode 2: fifoempty : fifo not empty bit 1 = receive fifo is not empty 0 = receive fifo is empty bit 6 mode 0: rxb1ovfl: receive buffer 1 overflow bit 1 = receive buffer 1 overflowed 0 = receive buffer 1 has not overflowed mode 1, 2: rxbnovfl: receive buffer overflow bit 1 = receive buffer has overflowed 0 = receive buffer has not overflowed bit 5 txbo: transmitter bus-off bit 1 = transmit error counter > 255 0 = transmit error counter 255 bit 4 txbp: transmitter bus passive bit 1 = transmit error counter > 127 0 = transmit error counter 127 bit 3 rxbp: receiver bus passive bit 1 = receive error counter > 127 0 = receive error counter 127 bit 2 txwarn: transmitter warning bit 1 = 127 transmit error counter > 95 0 = transmit error counter 95 bit 1 rxwarn: receiver warning bit 1 = 127 receive error counter > 95 0 = receive error counter 95 bit 0 ewarn: error warning bit this bit is a flag of the rxwarn and txwarn bits. 1 = the rxwarn or the txwarn bits are set 0 = neither the rxwarn or the txwarn bits are set legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 285 pic18f6585/8585/6680/8680 23.2.2 dedicated can transmit buffer registers this section describes the dedicated can transmit buffer registers and their associated control registers. register 23-5: txbncon: transmit buffer n control registers [0 n 2] mode 0 u-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 ? txabt txlarb txerr txreq ? txpri1 txpri0 mode 1, 2 r/c-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 txbif txabt txlarb txerr txreq ? txpri1 txpri0 bit 7 bit 0 bit 7 mode 0: unimplemented: read as ? 0 ? mode 1, 2: txbif: transmit buffer interrupt flag bit 1 = transmit buffer has completed transmission of message and may be reloaded 0 = transmit buffer has not completed transmission of a message bit 6 txabt: transmission aborted status bit (1) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (1) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (1) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (2) 1 = requests sending a message. clears the txabt, txlarb, and txerr bits. 0 = automatically cleared when the message is successfully sent note: clearing this bit in software while the bit is set, will request a message abort. bit 2 unimplemented: read as ? 0 ? bit 1-0 txpri1:txpri0: transmit priority bits (3) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: this bit is automatically cleared when txreq is set. 2: while txreq is set, transmit buffer registers remain read-only. 3: these bits define the order in which transmit buffers will be transferred. they do not alter the can message identifier. legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared
pic18f6585/8585/6680/8680 ds30491c-page 286 ? 2004 microchip technology inc. register 23-6: txbnsidh: transmit buffer n standard identifier registers, high byte [0 n 2] register 23-7: txbnsidl: transmit buffer n standard identifier registers, low byte [0 n 2] register 23-8: txbneidh: transmit buffer n extended identifier registers, high byte [0 n 2] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits, if exide (txbnsidl<3>) = 0 ; extended identifier bits eid28:eid21, if exide = 1 . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits, if exide (txbnsidl<3>) = 0 ; extended identifier bits eid20:eid18, if exide = 1 . bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = message will transmit extended id, sid10:sid0 becomes eid28:eid18 0 = message will transmit standard id, eid17:eid0 are ignored bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits (not used when transmitting standard identifier message) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 287 pic18f6585/8585/6680/8680 register 23-9: txbneidl: transmit buffe r n extended identifier registers, low byte [0 n 2] register 23-10: txbndm: transmit buffer n data field byte m registers [0 n 2, 0 m 7] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits (not used when transmitting standard identifier message) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x txbndm7 txbndm6 txbndm5 txbndm4 txbndm3 txbndm2 txbndm1 txbndm0 bit 7 bit 0 bit 7-0 txbndm7:txbndm0: transmit buffer n data field byte m bits (where 0 n < 3 and 0 m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 288 ? 2004 microchip technology inc. register 23-11: txbndlc: transmit buffer n data length code registers [0 n 2 ] register 23-12: txerrcnt: transmit error count register u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmit remote frame transmission request bit 1 = transmitted message will have txrtr bit set 0 = transmitted message will have txrtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc3:dlc0: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 bit 7 bit 0 bit 7-0 tec7:tec0: transmit error counter bits this register contains a value which is derived from the rate at which errors occur. when the error count overflows, the bus-off state occurs. when the bus has 128 occurrences of 11 consecutive recessive bits, the counter value is cleared. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 289 pic18f6585/8585/6680/8680 example 23-3: transmitting a can message using banked method ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. and since we want banked method, we need to make sure ; that correct bank is selected. banksel txb0con ; one banksel in beginning will make sure that we are ; in correct bank for rest of the buffer access. ; now load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf txb0d0 ; compiler will automatically set ?banked? bit ; load rest of data bytes - up to 8 bytes into txb0 buffer. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf txb0sidl movlw 24h ; load sid10:sid3 movwf txb0sidh ; no need to load txb0eidl:txb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf txb0con ; if required, wait for message to get transmitted btfsc txb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted.
pic18f6585/8585/6680/8680 ds30491c-page 290 ? 2004 microchip technology inc. example 23-4: transmitting a can message using win bits ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. use win bits to map it to rxb0 area. movf cancon, w ; win bits are in lower 4 bits only. read cancon ; register to preserve all other bits. if operation ; mode is already known, there is no need to preserve ; other bits. andlw b?11110000? ; clear win bits. iorlw b?00001000? ; select transmit buffer 0 movwf cancon ; apply the changes. ; now txb0 is mapped in place of rxb0. all future access to rxb0 registers will actually ; yield txb0 register values. ; load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf rxb0d0 ; access txb0d0 via rxb0d0 address. ; load rest of the data bytes - up to 8 bytes into ?txb0? buffer using rxb0 registers. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf rxb0sidl movlw 24h ; load sid10:sid3 movwf rxb0sidh ; no need to load rxb0eidl:rxb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf rxb0con ; if required, wait for message to get transmitted btfsc rxb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted. ; if required, reset the win bits to default state.
? 2004 microchip technology inc. ds30491c-page 291 pic18f6585/8585/6680/8680 23.2.3 dedicated can receive buffer registers this section shows the dedicated can receive buffer registers with their associated control registers. register 23-13: rxb0con: receive buffer 0 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful rxm1 rxm0 ? rxrtrro rxb0dben jtoff filhit0 mode 1, 2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message note: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and buffer will be considered full. bit 6 mode 0: rxm1: receive buffer mode bit 1; combines with rxm0 to form rxm<1:0> bits (see bit 5) 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier, exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per exiden bit in rxfnsidl register mode 1, 2: rxm1 : receive buffer mode bit 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm0: receive buffer mode bit 0; combines with rxm1 to form rxm<1:0> bits (see bit 6) mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0: unimplemented: read as ? 0 ? mode 1, 2: filhit4: filter hit bit 4 this bit combines with other bits to form filter acceptance bits <4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit3: filter hit bit 3 this bit combines with other bits to form filter acceptance bits <4:0>. legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared
pic18f6585/8585/6680/8680 ds30491c-page 292 ? 2004 microchip technology inc. register 23-13: rxb0con: receive buffer 0 control register (continued) bit 2 mode 0: rxb0dben: receive buffer 0 double-buffer enable bit 1 = receive buffer 0 overflow will write to receive buffer 1 0 = no receive buffer 0 overflow to receive buffer 1 mode 1, 2: filhit2: filter hit bit 2 this bit combines with other bits to form filter acceptance bits <4:0>. bit 1 mode 0: jtoff: jump table offset bit (read-only copy of rxb0dben) 1 = allows jump table offset between 6 and 7 0 = allows jump table offset between 1 and 0 note: this bit allows same filter jump table for both rxb0con and rxb1con. mode 1, 2: filhit1: filter hit bit 1 this bit combines with other bits to form filter acceptance bits <4:0>. bit 0 mode 0: filhit0: filter hit bit 0 this bit indicates which acceptance filter enabled the message reception into receive buffer 0. 1 = acceptance filter 1 (rxf1) 0 = acceptance filter 0 (rxf0) mode 1, 2: filhit0: filter hit bit 0 this bit, in combination with filhit<4:1>, indicates which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared
? 2004 microchip technology inc. ds30491c-page 293 pic18f6585/8585/6680/8680 register 23-14: rxb1con: receive buffer 1 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful rxm1 rxm0 ? rxrtrro filhit2 filhit1 filhit0 mode 1, 2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message note: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and buffer will be considered full. bit 6 mode 0: rxm1: receive buffer mode bit 1; combines with rxm0 to form rxm<1:0> bits (see bit 5) 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier, exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per exiden bit in rxfnsidl register mode 1, 2: rxm1: receive buffer mode bit 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm0: receive buffer mode bit 0; combines with rxm1 to form rxm<1:0> bits (see bit 6) mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0: unimplemented: read as ? 0 ? mode 1, 2: filhit4: filter hit bit 4 this bit combines with other bits to form filter acceptance bits <4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit3: filter hit bit 3 this bit combines with other bits to form filter acceptance bits <4:0>. bit 2-0 mode 0: filhit2:filhit0: filter hit bits these bits indicate which acceptance filter enabled the last message reception into receive buffer 1. 111 = reserved 110 = reserved 101 = acceptance filter 5 (rxf5) 100 = acceptance filter 4 (rxf4) 011 = acceptance filter 3 (rxf3) 010 = acceptance filter 2 (rxf2) 001 = acceptance filter 1 (rxf1), only possible when rxb0dben bit is set 000 = acceptance filter 0 (rxf0), only possible when rxb0dben bit is set mode 1, 2: filhit2:filhit0 filter hit bits <2:0> these bits, in combination with filhit<4:3>, indicate which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared
pic18f6585/8585/6680/8680 ds30491c-page 294 ? 2004 microchip technology inc. register 23-15: rxbnsidh: receive buffer n standard identifier registers, high byte [0 n 1] register 23-16: rxbnsidl: receive buffer n standard identifier registers, low byte [0 n 1] register 23-17: rxbneidh: receive buffer n extended identifier registers, high byte [0 n 1] r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits, if exid = 0 (rxbnsidl<3>); extended identifier bits eid28:eid21, if exid = 1 . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exid ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits, if exid = 0 ; extended identifier bits eid20:eid18, if exid = 1 . bit 4 srr: substitute remote request bit this bit is always ? 0 ? when exid = 1 or equal to the value of rxrtrro (rbxncon<3>) when exid = 0 . bit 3 exid: extended identifier bit 1 = received message is an extended data frame, sid10:sid0 are eid28:eid18 0 = received message is a standard data frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 295 pic18f6585/8585/6680/8680 register 23-18: rxbneidl: receive buffer n extended identifier registers, low byte [0 n 1] register 23-19: rxbndlc: receive buffer n data length code registers [0 n 1 ] r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = remote transfer request 0 = no remote transfer request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc3:dlc0: data length code bits 1111 = invalid 1110 = invalid 1101 = invalid 1100 = invalid 1011 = invalid 1010 = invalid 1001 = invalid 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 296 ? 2004 microchip technology inc. register 23-20: rxbndm: receive buffer n data field byte m registers [0 n 1, 0 m 7] register 23-21: rxerrcnt: receive error count register example 23-5: reading a can message r-x r-x r-x r-x r-x r-x r-x r-x rxbndm7 rxbndm6 rxbndm5 rxbndm4 r xbndm3 rxbndm2 rxbndm1 rxbndm0 bit 7 bit 0 bit 7-0 rxbndm7:rxbndm0: receive buffer n data field byte m bits (where 0 n < 1 and 0 < m < 7) each receive buffer has an array of registers. for example, receive buffer 0 has 8 registers: rxb0d0 to rxb0d7. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 rec7 rec6 rec5 rec4 rec3 rec2 rec1 rec0 bit 7 bit 0 bit 7-0 rec7:rec0: receive error counter bits this register contains the receive error value as defined by the can specifications. when rxerrcnt > 127, the module will go into an error-passive state. rxerrcnt does not have the ability to put the module in ?bus-off? state. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown ; need to read a pending message from rxb0 buffer. ; to receive any message, filter, mask and rxm1:rxm0 bits in rxb0con registers must be ; programmed correctly. ; ; make sure that there is a message pending in rxb0. btfss rxb0con, rxful ; does rxb0 contain a message? bra nomessage ; no. handle this situation... ; we have verified that a message is pending in rxb0 buffer. ; if this buffer can receive both standard or extended identifier messages, ; identify type of message received. btfss rxb0sidl, exid ; is this extended identifier? bra standardmessage ; no. this is standard identifier message. ; yes. this is extended identifier message. ; read all 29-bits of extended identifier message. ... ; now read all data bytes movff rxb0do, my_data_byte1 ... ; once entire message is read, mark the rxb0 that it is read and no longer full. bcf rxb0con, rxful ; this will allow can module to load new messages ; into this buffer. ...
? 2004 microchip technology inc. ds30491c-page 297 pic18f6585/8585/6680/8680 23.2.3.1 programmable tx/rx and auto rtr buffers the ecan module contains 6 message buffers that can be programmed as transmit or receive buffers. any of these buffers can also be programmed to automatically handle rtr messages. register 23-22: bncon: tx/rx buffer n control registers in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) note: these registers are not used in mode 0. r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit (1) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message note: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and buffer will be considered full. bit 6 rxm1: receive buffer mode bit 1 = receive all messages including partial and invalid (acceptance filters are ignored) 0 = receive all valid messages as per acceptance filters bit 5 rtrro: read-only remote transmission request bit for received message 1 = received message is a remote transmission request 0 = received message is not a remote transmission request bit 4-0 filhit4:filhit0: filter hit bits these bits indicate which acceptance filter enabled the last message reception into this buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00001 = acceptance filter 1 (rxf1) 00000 = acceptance filter 0 (rxf0) note 1: these registers are available in mode 1 and 2 only. legend: u = unimplemented bit, read as ?0? - n = value at por c = clearable bit r = readable bit w = writable bit x = bit is unknown ?1? = bit is set ?0? = bit is cleared
pic18f6585/8585/6680/8680 ds30491c-page 298 ? 2004 microchip technology inc. register 23-23: bncon: tx/rx buffer n control registers in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r/w-0 r-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 txbif txabt txlarb txerr txreq rtren txpri1 txpri0 bit 7 bit 0 bit 7 txbif: transmit buffer interrupt flag bit (1) 1 = a message is successfully transmitted 0 = no message was transmitted bit 6 txabt: transmission aborted status bit (1) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (2) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (2) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (3) 1 = requests sending a message; clears the txabt, txlarb, and txerr bits 0 = automatically cleared when the message is successfully sent note: clearing this bit in software while the bit is set will request a message abort. bit 2 rtren: automatic remote transmission request enable bit 1 = when a remote transmission request is received, txreq will be automatically set 0 = when a remote transmission request is received, txreq will be unaffected bit 1-0 txpri1:txpri0: transmit priority bits (4) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: these registers are available in mode 1 and 2 only. 2: this bit is automatically cleared when txreq is set. 3: while txreq is set or transmission is in progress, transmit buffer registers remain read-only. 4: these bits set the order in which the transmit buffer will be transferred. they do not alter the can message identifier. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 299 pic18f6585/8585/6680/8680 register 23-24: bnsidh: tx/rx buffer n standard identifier registers, high byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-25: bnsidh: tx/rx buffer n standard identifier registers, high byte in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits, if exide (bnsidl<3>) = 0 ; extended identifier bits eid28:eid21, if exide = 1 . note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits, if exide (bnsidl<3>) = 0 ; extended identifier bits eid28:eid21, if exide = 1 . note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 300 ? 2004 microchip technology inc. register 23-26: bnsidl: tx/rx buffer n standard identifier registers, low byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-27: bnsidl: tx/rx buffer n standard identifier registers, low byte in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exid ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits, if exid = 0 ; extended identifier bits eid20:eid18, if exid = 1 . bit 4 srr: substitute remote transmission request bit (only when exid = 1 ) 1 = remote transmission request occurred 0 = no remote transmission request occurred bit 3 exid: extended identifier enable bit 1 = received message is an extended identifier frame, sid10:sid0 are eid28:eid18 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits, if exide = 0 ; extended identifier bits eid20:eid18, if exide = 1 . bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = received message is an extended identifier frame, sid10:sid0 are eid28:eid18 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 301 pic18f6585/8585/6680/8680 register 23-28: bneidh: tx/rx buffer n extended identifier registers, high byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-29: bneidh: tx/rx buffer n extended identifier registers, high byte in transmit mode [0 n 5, txnen (bsel0) = 1] (1) r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 302 ? 2004 microchip technology inc. register 23-30: bneidl: tx/rx buffer n extended identifier registers, low byte in receive mode [0 n 5, txnen (bsel) = 0 ] (1) register 23-31: bneidl: tx/rx buffer n extended identifier registers, low byte in transmit mode [0 n 5, txnen (bsel) = 1 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 303 pic18f6585/8585/6680/8680 register 23-32: bndm: tx/rx buffer n data field byte m registers in receive mode [0 n 5, 0 m 7, txnen (bsel) = 0 ] (1) register 23-33: bndm: tx/rx buffer n data field byte m registers in transmit mode [0 n 5, 0 m 7, txnen (bsel) = 1 ] (1) r-xr-xr-xr-xr-xr-xr-xr-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 bit 7-0 bndm7:bndm0: receive buffer n data field byte m bits (where 0 n < 3 and 0 < m < 8) each receive buffer has an array of registers. for example, receive buffer 0 has 7 registers: b0d0 to b0d7. note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 bit 7-0 bndm7:bndm0: transmit buffer n data field byte m bits (where 0 n < 3 and 0 < m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7. note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 304 ? 2004 microchip technology inc. register 23-34: bndlc: tx/rx buffer n data length code registers in receive mode [0 n 5, txnen (bsel) = 0 ] (1) u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = this is a remote transmission request 0 = this is not a remote transmission request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc3:dlc0: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 305 pic18f6585/8585/6680/8680 register 23-35: bndlc: tx/rx buffer n data length code registers in transmit mode [0 n 5, txnen (bsel) = 1 ] (1) register 23-36: bsel0: buffer select register 0 (1) u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmitter remote transmission request bit 1 = transmitted message will have rtr bit set 0 = transmitted message will have rtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc3:dlc0: data length code bits 1111 - 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 b5txen b4txen b3txen b2txen b1txen b0txen ? ? bit 7 bit 0 bit 7-2 b5txen:b0txen: buffer 5 to buffer 0 transmit enable bit 1 = buffer is configured in transmit mode 0 = buffer is configured in receive mode bit 1-0 unimplemented: read as ? 0 ? note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 306 ? 2004 microchip technology inc. 23.2.3.2 message acceptance filters and masks this subsection describes the message acceptance filters and masks for the can receive buffers. register 23-37: rxfnsidh: receive acceptance filter n standard identifier filter registers, high byte [0 n 15] (1) register 23-38: rxfnsidl: receive acceptance filter n standard identifier filter registers, low byte [0 n 15] (1) note: these registers are writable in configuration mode only. r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier filter bits, if exiden = 0 ; extended identifier filter bits eid28:eid21, if exiden = 1 . note 1: registers rxf6sidh:rxf15sidh are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier filter bits, if exiden = 0 ; extended identifier filter bits eid20:eid18, if exiden = 1 . bit 4 unimplemented: read as ? 0 ? bit 3 exiden: extended identifier filter enable bit 1 = filter will only accept extended id messages 0 = filter will only accept standard id messages note: in mode 0, this bit must be set/cleared as required, irrespective of corresponding mask register value. bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier filter bits note 1: registers rxf6sidl:rxf15sidl are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 307 pic18f6585/8585/6680/8680 register 23-39: rxfneidh: receive acceptance filter n extended identifier registers, high byte [0 n 15] (1) register 23-40: rxfneidl: receive acceptance filter n extended identifier registers, low byte [0 n 15] (1) register 23-41: rxmnsidh: receive acceptance mask n standard identifier mask registers, high byte [0 n 1] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier filter bits note 1: registers rxf6eidh:rxf15eidh are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier filter bits note 1: registers rxf6eidl:rxf15eidl are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier mask bits, or extended identifier mask bits eid28:eid21 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 308 ? 2004 microchip technology inc. register 23-42: rxmnsidl: receive acceptance mask n standard identifier mask registers, low byte [0 n 1] register 23-43: rxmneidh: receive acceptance mask n extended identifier mask registers, high byte [0 n 1] register 23-44: rxmneidl: receive acceptance mask n extended identifier mask registers, low byte [0 n 1] r/w-x r/w-x r/w-x u-0 r/w-0 u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden (1) ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier mask bits, or extended identifier mask bits eid20:eid18 bit 4 unimplemented: read as ? 0 ? bit 3 mode 0: unimplemented: read as ? 0 ? mode 1, 2 : exiden: extended identifier filter enable mask bit (1) 1 = messages selected by exiden bit in rxfnsidl will be accepted 0 = both standard and extended identifier messages will be accepted note 1: this bit is available in mode 1 and 2 only. bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 309 pic18f6585/8585/6680/8680 register 23-45: sdflc: standard data bytes filter length count register (1) register 23-46: rxfconn: receive filter control register n [0 n 1] (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? flc4flc3flc2flc1flc0 bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-0 flc4:flc0: filter length count bits mode 0: not used; forced to ? 00000 ?. mode 1, 2: 00000 - 10010 = 0 18 bits are available for standard data byte filter. actual number of bits used depends on dlc3:dlc0 bits (rxbndlc<3:0> or bndlc<3:0> if configured as rx buffer) of message being received. if dlc3:dlc0 = 0000 no bits will be compared with incoming data bits if dlc3:dlc0 = 0001 up to 8 data bits of rxfneid<7:0>, as determined by flc2:flc0, will be compared with the corresponding number of data bits of the incoming message if dlc3:dlc0 = 0010 up to 16 data bits of rxfneid<15:0>, as determined by flc3:flc0, will be compared with the corresponding number of data bits of the incoming message if dlc3:dlc0 = 0011 up to 18 data bits of rxfneid<17:0>, as determined by flc4:flc0, will be compared with the corresponding number of data bits of the incoming message note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown rxfcon0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rxf7en rxf6en rxf5en rxf4en rxf3en rxf2en rxf1en rxf0en rxfcon1 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 rxf15en rxf14en rxf13en rxf12en rxf11en rxf10en rxf9en rxf8en bit 7 bit 0 bit 7-0 rxfnen: receive filter n enable bit 0 = filter is disabled 1 = filter is enabled note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 310 ? 2004 microchip technology inc. register 23-47: rxfbconn: receive filter buffer control register n (1) rxfbcon0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f1bp_3 f1bp_2 f1bp_1 f1bp_0 f 0bp_3 f0bp_2 f0bp_1 f0bp_0 rxfbcon1 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f3bp_3 f3bp_2 f3bp_1 f3bp_0 f 2bp_3 f2bp_2 f2bp_1 f2bp_0 rxfbcon2 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f5bp_3 f5bp_2 f5bp_1 f5bp_0 f 4bp_3 f4bp_2 f4bp_1 f4bp_0 rxfbcon3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f7bp_3 f7bp_2 f7bp_1 f7bp_0 f 6bp_3 f6bp_2 f6bp_1 f6bp_0 rxfbcon4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f9bp_3 f9bp_2 f9bp_1 f9bp_0 f 8bp_3 f8bp_2 f8bp_1 f8bp_0 rxfbcon5 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f11bp_3 f11bp_2 f11bp_1 f11bp_0 f10bp_3 f10bp_2 f10bp_1 f10bp_0 rxfbcon6 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f13bp_3 f13bp_2 f13bp_1 f13bp_0 f12bp_3 f12bp_2 f12bp_1 f12bp_0 rxfbcon7 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f15bp_3 f15bp_2 f15bp_1 f15bp_0 f14bp_3 f14bp_2 f14bp_1 f14bp_0 bit 7 bit 0 bit 7-0 fnbp_3:fnbp_0: filter n buffer pointer nibble bits 0000 = filter n is associated with rxb0 0001 = filter n is associated with rxb1 0010 = filter n is associated with b0 0011 = filter n is associated with b1 . . . 0111 = filter n is associated with b5 1111:1000 = reserved note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 311 pic18f6585/8585/6680/8680 register 23-48: msel0: mask select register 0 (1) r/w-0 r/w-1 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 fil3_1 fil3_0 fil2_1 fil2_0 fil1_1 fil1_0 fil0_1 fil0_0 bit 7 bit 0 bit 7-6 fil3_1:fil3_0: filter 3 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil2_1:fil2_0: filter 2 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil1_1:fil1_0: filter 1 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil0_1:fil0_0: filter 0 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 312 ? 2004 microchip technology inc. register 23-49: msel1: mask select register 1 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 fil7_1 fil7_0 fil6_1 fil6_0 fil5_1 fil5_0 fil4_1 fil4_0 bit 7 bit 0 bit 7-6 fil7_1:fil7_0: filter 7 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil6_1:fil6_0: filter 6 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil5_1:fil5_0: filter 5 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil4_1:fil4_0: filter 4 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 313 pic18f6585/8585/6680/8680 register 23-50: msel2: mask select register 2 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil11_1 fil11_0 fil10_1 fil10_0 fil9_1 fil9_0 fil8_1 fil8_0 bit 7 bit 0 bit 7-6 fil11_1:fil11_0: filter 11 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil10_1:fil10_0: filter 10 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil9_1:fil9_0: filter 9 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil8_1:fil8_0: filter 8 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 314 ? 2004 microchip technology inc. register 23-51: msel3: mask select register 3 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil15_1 fil15_0 fil14_1 fil14_0 fil13_1 fil13_0 fil12_1 fil12_0 bit 7 bit 0 bit 7-6 fil15_1:fil15_0: filter 15 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil14_1:fil14_0: filter 14 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil13_1:fil13_0: filter 13 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil12_1:fil12_0: filter 12 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 315 pic18f6585/8585/6680/8680 23.2.4 can baud rate registers this subsection describes the can baud rate registers. register 23-52: brgcon1: baud rate contro l register 1 note: these registers are writable in configuration mode only. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 bit 7 bit 0 bit 7-6 sjw1:sjw0: synchronized jump width bits 11 = synchronization jump width time = 4 x t q 10 = synchronization jump width time = 3 x t q 01 = synchronization jump width time = 2 x t q 00 = synchronization jump width time = 1 x t q bit 5-0 brp5:brp0: baud rate prescaler bits 111111 = t q = (2 x 64)/f osc 111110 = t q = (2 x 63)/f osc . . . 000001 = t q = (2 x 2)/f osc 000000 = t q = (2 x 1)/f osc legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 316 ? 2004 microchip technology inc. register 23-53: brgcon2: baud rate contro l register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 seg2phts sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 bit 7 bit 0 bit 7 seg2phts: phase segment 2 time select bit 1 = freely programmable 0 = maximum of pheg1 or information processing time (ipt), whichever is greater bit 6 sam: sample of the can bus line bit 1 = bus line is sampled three times prior to the sample point 0 = bus line is sampled once at the sample point bit 5-3 seg1ph2:seg1ph0: phase segment 1 bits 111 = phase segment 1 time = 8 x t q 110 = phase segment 1 time = 7 x t q 101 = phase segment 1 time = 6 x t q 100 = phase segment 1 time = 5 x t q 011 = phase segment 1 time = 4 x t q 010 = phase segment 1 time = 3 x t q 001 = phase segment 1 time = 2 x t q 000 = phase segment 1 time = 1 x t q bit 2-0 prseg2:prseg0: propagation time select bits 111 = propagation time = 8 x t q 110 = propagation time = 7 x t q 101 = propagation time = 6 x t q 100 = propagation time = 5 x t q 011 = propagation time = 4 x t q 010 = propagation time = 3 x t q 001 = propagation time = 2 x t q 000 = propagation time = 1 x t q legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 317 pic18f6585/8585/6680/8680 register 23-54: brgcon3: baud rate contro l register 3 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 wakdis wakfil ? ? ? seg2ph2 (1) seg2ph1 (1) seg2ph0 (1) bit 7 bit 0 bit 7 wakdis: wake-up disable bit 1 = disable can bus activity wake-up feature 0 = enable can bus activity wake-up feature bit 6 wakfil: selects can bus line filter for wake-up bit 1 = use can bus line filter for wake-up 0 = can bus line filter is not used for wake-up bit 5-3 unimplemented: read as ? 0 ? bit 2-0 seg2ph2:seg2ph0: phase segment 2 time select bits (1) 111 = phase segment 2 time = 8 x t q 110 = phase segment 2 time = 7 x t q 101 = phase segment 2 time = 6 x t q 100 = phase segment 2 time = 5 x t q 011 = phase segment 2 time = 4 x t q 010 = phase segment 2 time = 3 x t q 001 = phase segment 2 time = 2 x t q 000 = phase segment 2 time = 1 x t q note 1: ignored if seg2phts bit (brgcon2<7>) is ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 318 ? 2004 microchip technology inc. 23.2.5 can module i/o control register this register controls the operation of the can module?s i/o pins in relation to the rest of the microcontroller. register 23-55: ciocon: can i/o control register r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 tx2src tx2en endrhi cancap ? ? ? ? bit 7 bit 0 bit 7 tx2src : cantx2 pin data source bit 1 = cantx2 pin will output the can clock 0 = cantx2 pin will output cantx1 bit 6 tx2en : cantx2 pin enable bit 1 = cantx2 pin will output cantx1 or can clock as selected by tx2src bit 0 = cantx2 pin will have digital i/o function bit 5 endrhi: enable drive high bit (1) 1 = cantx pin will drive v dd when recessive 0 = cantx pin will be tri-state when recessive bit 4 cancap: can message receive capture enable bit 1 = enable can capture, can message receive signal replaces input on rc2/ccp1 0 = disable can capture, rc2/ccp1 input to ccp1 module bit 3-0 unimplemented: read as ? 0 ? note 1: always set this bit when using differential bus to avoid signal crosstalk in cantx from other nearby pins. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 319 pic18f6585/8585/6680/8680 23.2.6 can interrupt registers the registers in this section are the same as described in section 9.0 ?interrupts? . they are duplicated here for convenience. register 23-56: pir3: peripheral interrupt flag register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txb2if/ txbnif txb1if (1) txb0if (1) rxb1if/ rxbnif rxb0if/ fifowmif bit 7 bit 0 bit 7 irxif: can invalid received message interrupt flag bit 1 = an invalid message has occurred on the can bus 0 = no invalid message on can bus bit 6 wakif: can bus activity wake-up interrupt flag bit 1 = activity on can bus has occurred 0 = no activity on can bus bit 5 errif: can bus error interrupt flag bit 1 = an error has occurred in the can module (multiple sources) 0 = no can module errors bit 4 when can is in mode 0: txb2if: can transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message when can is in mode 1 or 2: txbnif: any transmit buffer interrupt flag bit 1 = one or more transmit buffers has completed transmission of a message and may be reloaded 0 = no transmit buffer is ready for reload bit 3 txb1if: can transmit buffer 1 interrupt flag bit (1) 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: can transmit buffer 0 interrupt flag bit (1) 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 when can is in mode 0: rxb1if: can receive buffer 1 interrupt flag bit 1 = receive buffer 1 has received a new message 0 = receive buffer 1 has not received a new message when can is in mode 1 or 2: rxbnif: any receive buffer interrupt flag bit 1 = one or more receive buffers has received a new message 0 = no receive buffer has received a new message bit 0 when can is in mode 0: rxb0if: can receive buffer 0 interrupt flag bit 1 = receive buffer 0 has received a new message 0 = receive buffer 0 has not received a new message when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmif: fifo watermark interrupt flag bit 1 = fifo high watermark is reached 0 = fifo high watermark is not reached note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 320 ? 2004 microchip technology inc. register 23-57: pie3: peripheral interrupt enable register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txb2ie/ txbnie txb1ie (1) txb0ie (1) rxb1ie/ rxbnie rxb0ie/ fifowmie bit 7 bit 0 bit 7 irxie: can invalid received message interrupt enable bit 1 = enable invalid message received interrupt 0 = disable invalid message received interrupt bit 6 wakie: can bus activity wake-up interrupt enable bit 1 = enable bus activity wake-up interrupt 0 = disable bus activity wake-up interrupt bit 5 errie: can bus error interrupt enable bit 1 = enable can bus error interrupt 0 = disable can bus error interrupt bit 4 when can is in mode 0: txb2ie: can transmit buffer 2 interrupt enable bit 1 = enable transmit buffer 2 interrupt 0 = disable transmit buffer 2 interrupt when can is in mode 1 or 2: txbnie: can transmit buffer interrupts enable bit 1 = enable transmit buffer interrupt; individual interrupt is enabled by txbie and bie0 0 = disable all transmit buffer interrupts bit 3 txb1ie: can transmit buffer 1 interrupt enable bit (1) 1 = enable transmit buffer 1 interrupt 0 = disable transmit buffer 1 interrupt bit 2 txb0ie: can transmit buffer 0 interrupt enable bit (1) 1 = enable transmit buffer 0 interrupt 0 = disable transmit buffer 0 interrupt bit 1 when can is in mode 0: rxb1ie: can receive buffer 1 interrupt enable bit 1 = enable receive buffer 1 interrupt 0 = disable receive buffer 1 interrupt when can is in mode 1 or 2: rxbnie: can receive buffer interrupts enable bit 1 = enable receive buffer interrupt; individual interrupt is enabled by bie0 0 = disable all receive buffer interrupts bit 0 when can is in mode 0: rxb0ie: can receive buffer 0 interrupt enable bit 1 = enable receive buffer 0 interrupt 0 = disable receive buffer 0 interrupt when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmie: fifo watermark interrupt enable bit 1 = enable fifo watermark interrupt 0 = disable fifo watermark interrupt note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 321 pic18f6585/8585/6680/8680 register 23-58: ipr3: peripheral interrupt priority register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txb2ip/ txbnip txb1ip (1) txb0ip (1) rxb1ip/ rxbnip rxb0ip/ fifowmip bit 7 bit 0 bit 7 irxip: can invalid received message interrupt priority bit 1 = high priority 0 = low priority bit 6 wakip: can bus activity wake-up interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can bus error interrupt priority bit 1 = high priority 0 = low priority bit 4 when can is in mode 0: txb2ip: can transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: txbnip: can transmit buffer interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: can transmit buffer 1 interrupt priority bit (1) 1 = high priority 0 = low priority bit 2 txb0ip: can transmit buffer 0 interrupt priority bit (1) 1 = high priority 0 = low priority bit 1 when can is in mode 0: rxb1ip: can receive buffer 1 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: rxbnip: can receive buffer interrupts priority bit 1 = high priority 0 = low priority bit 0 when can is in mode 0: rxb0ip: can receive buffer 0 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmip: fifo watermark interrupt priority bit 1 = high priority 0 = low priority note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 322 ? 2004 microchip technology inc. register 23-59: txbie: transmit buffers interrupt enable register (1) register 23-60: bie0: buffer interrupt enable register 0 (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 ? ? ? txb2ie txb1ie txb0ie ? ? bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-2 tx2bie:txb0ie: transmit buffer 2-0 interrupt enable bit (2) 1 = transmit buffer interrupt is enabled 0 = transmit buffer interrupt is disabled bit 1-0 unimplemented: read as ? 0 ? note 1: this register is available in mode 1 and 2 only. 2: txbie in pie3 register must be set to get an interrupt. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 b5ie b4ie b3ie b2ie b1ie b0ie rxb1ie rxb0ie bit 7 bit 0 bit 7-2 b5ie:b0ie: programmable transmit/receive buffer 5-0 interrupt enable bit (2) 1 = interrupt is enabled 0 = interrupt is disabled bit 1-0 rxb1ie:rxb0ie: dedicated receive buffer 1-0 interrupt enable bit (2) 1 = interrupt is enabled 0 = interrupt is disabled note 1: this register is available in mode 1 and 2 only. 2: either txbie or rxbie in pie3 register must be set to get an interrupt. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. ds30491c-page 323 pic18f6585/8585/6680/8680 table 23-1: can controller register map address (1) name address name address name address name f7fh spbrgh (3) f5fh cancon_ro0 f3fh cancon_ro2 f1fh rxm1eidl f7eh baudcon (3) f5eh canstat_ro0 f3eh canstat_ro2 f1eh rxm1eidh f7dh ? (4) f5dh rxb1d7 f3dh txb1d7 f1dh rxm1sidl f7ch ? (4) f5ch rxb1d6 f3ch txb1d6 f1ch rxm1sidh f7bh ? (4) f5bh rxb1d5 f3bh txb1d5 f1bh rxm0eidl f7ah ? (4) f5ah rxb1d4 f3ah txb1d4 f1ah rxm0eidh f79h eccp1del (3) f59h rxb1d3 f39h txb1d3 f19h rxm0sidl f78h ? (4) f58h rxb1d2 f38h txb1d2 f18h rxm0sidh f77h ecancon f57h rxb1d1 f37h txb1d1 f17h rxf5eidl f76h txerrcnt f56h rxb1d0 f36h txb1d0 f16h rxf5eidh f75h rxerrcnt f55h rxb1dlc f35h txb1dlc f15h rxf5sidl f74h comstat f54h rxb1eidl f34h txb1eidl f14h rxf5sidh f73h ciocon f53h rxb1eidh f33h txb1eidh f13h rxf4eidl f72h brgcon3 f52h rxb1sidl f32h txb1sidl f12h rxf4eidh f71h brgcon2 f51h rxb1sidh f31h txb1sidh f11h rxf4sidl f70h brgcon1 f50h rxb1con f30h txb1con f10h rxf4sidh f6fh cancon f4fh cancon_ro1 (2) f2fh cancon_ro3 (2) f0fh rxf3eidl f6eh canstat f4eh canstat_ro1 (2) f2eh canstat_ro3 (2) f0eh rxf3eidh f6dh rxb0d7 f4dh txb0d7 f2dh txb2d7 f0dh rxf3sidl f6ch rxb0d6 f4ch txb0d6 f2ch txb2d6 f0ch rxf3sidh f6bh rxb0d5 f4bh txb0d5 f2bh txb2d5 f0bh rxf2eidl f6ah rxb0d4 f4ah txb0d4 f2ah txb2d4 f0ah rxf2eidh f69h rxb0d3 f49h txb0d3 f29h txb2d3 f09h rxf2sidl f68h rxb0d2 f48h txb0d2 f28h txb2d2 f08h rxf2sidh f67h rxb0d1 f47h txb0d1 f27h txb2d1 f07h rxf1eidl f66h rxb0d0 f46h txb0d0 f26h txb2d0 f06h rxf1eidh f65h rxb0dlc f45h txb0dlc f25h txb2dlc f05h rxf1sidl f64h rxb0eidl f44h txb0eidl f24h txb2eidl f04h rxf1sidh f63h rxb0eidh f43h txb0eidh f23h txb2eidh f03h rxf0eidl f62h rxb0sidl f42h txb0sidl f22h txb2sidl f02h rxf0eidh f61h rxb0sidh f41h txb0sidh f21h txb2sidh f01h rxf0sidl f60h rxb0con f40h txb0con f20h txb2con f00h rxf0sidh note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f6585/8585/6680/8680 ds30491c-page 324 ? 2004 microchip technology inc. effh ? (4) edfh ? (4) ebfh ? (4) e9fh ? (4) efeh ? (4) edeh ? (4) ebeh ? (4) e9eh ? (4) efdh ? (4) eddh ? (4) ebdh ? (4) e9dh ? (4) efch ? (4) edch ? (4) ebch ? (4) e9ch ? (4) efbh ? (4) edbh ? (4) ebbh ? (4) e9bh ? (4) efah ? (4) edah ? (4) ebah ? (4) e9ah ? (4) ef9h ? (4) ed9h ? (4) eb9h ? (4) e99h ? (4) ef8h ? (4) ed8h ? (4) eb8h ? (4) e98h ? (4) ef7h ? (4) ed7h ? (4) eb7h ? (4) e97h ? (4) ef6h ? (4) ed6h ? (4) eb6h ? (4) e96h ? (4) ef5h ? (4) ed5h ? (4) eb5h ? (4) e95h ? (4) ef4h ? (4) ed4h ? (4) eb4h ? (4) e94h ? (4) ef3h ? (4) ed3h ? (4) eb3h ? (4) e93h ? (4) ef2h ? (4) ed2h ? (4) eb2h ? (4) e92h ? (4) ef1h ? (4) ed1h ? (4) eb1h ? (4) e91h ? (4) ef0h ? (4) ed0h ? (4) eb0h ? (4) e90h ? (4) eefh ? (4) ecfh ? (4) eafh ? (4) e8fh ? (4) eeeh ? (4) eceh ? (4) eaeh ? (4) e8eh ? (4) eedh ? (4) ecdh ? (4) eadh ? (4) e8dh ? (4) eech ? (4) ecch ? (4) each ? (4) e8ch ? (4) eebh ? (4) ecbh ? (4) eabh ? (4) e8bh ? (4) eeah ? (4) ecah ? (4) eaah ? (4) e8ah ? (4) ee9h ? (4) ec9h ? (4) ea9h ? (4) e89h ? (4) ee8h ? (4) ec8h ? (4) ea8h ? (4) e88h ? (4) ee7h ? (4) ec7h ? (4) ea7h ? (4) e87h ? (4) ee6h ? (4) ec6h ? (4) ea6h ? (4) e86h ? (4) ee5h ? (4) ec5h ? (4) ea5h ? (4) e85h ? (4) ee4h ? (4) ec4h ? (4) ea4h ? (4) e84h ? (4) ee3h ? (4) ec3h ? (4) ea3h ? (4) e83h ? (4) ee2h ? (4) ec2h ? (4) ea2h ? (4) e82h ? (4) ee1h ? (4) ec1h ? (4) ea1h ? (4) e81h ? (4) ee0h ? (4) ec0h ? (4) ea0h ? (4) e80h ? (4) table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
? 2004 microchip technology inc. ds30491c-page 325 pic18f6585/8585/6680/8680 e7fh cancon_ro4 (2) e5fh cancon_ro6 (2) e3fh cancon_ro8 (2) e1fh ? (4) e7eh canstat_ro4 (2) e5eh canstat_ro6 (2) e3eh canstat_ro8 (2) e1eh ? (4) e7dh b5d7 e5dh b3d7 e3dh b1d7 e1dh ? (4) e7ch b5d6 e5ch b3d6 e3ch b1d6 e1ch ? (4) e7bh b5d5 e5bh b3d5 e3bh b1d5 e1bh ? (4) e7ah b5d4 e5ah b3d4 e3ah b1d4 e1ah ? (4) e79h b5d3 e59h b3d3 e39h b1d3 e19h ? (4) e78h b5d2 e58h b3d2 e38h b1d2 e18h ? (4) e77h b5d1 e57h b3d1 e37h b1d1 e17h ? (4) e76h b5d0 e56h b3d0 e36h b1d0 e16h ? (4) e75h b5dlc e55h b3dlc e35h b1dlc e15h ? (4) e74h b5eidl e54h b3eidl e34h b1eidl e14h ? (4) e73h b5eidh e53h b3eidh e33h b1eidh e13h ? (4) e72h b5sidl e52h b3sidl e32h b1sidl e12h ? (4) e71h b5sidh e51h b3sidh e31h b1sidh e11h ? (4) e70h b5con e50h b3con e30h b1con e10h ? (4) e6fh cancon_ro5 e4fh cancon_ro7 e2fh cancon_ro9 e0fh ? (4) e6eh canstat_ro5 e4eh canstat_ro7 e2eh canstat_ro9 e0eh ? (4) e6dh b4d7 e4dh b2d7 e2dh b0d7 e0dh ? (4) e6ch b4d6 e4ch b2d6 e2ch b0d6 e0ch ? (4) e6bh b4d5 e4bh b2d5 e2bh b0d5 e0bh ? (4) e6ah b4d4 e4ah b2d4 e2ah b0d4 e0ah ? (4) e69h b4d3 e49h b2d3 e29h b0d3 e09h ? (4) e68h b4d2 e48h b2d2 e28h b0d2 e08h ? (4) e67h b4d1 e47h b2d1 e27h b0d1 e07h ? (4) e66h b4d0 e46h b2d0 e26h b0d0 e06h ? (4) e65h b4dlc e45h b2dlc e25h b0dlc e05h ? (4) e64h b4eidl e44h b2eidl e24h b0eidl e04h ? (4) e63h b4eidh e43h b2eidh e23h b0eidh e03h ? (4) e62h b4sidl e42h b2sidl e22h b0sidl e02h ? (4) e61h b4sidh e41h b2sidh e21h b0sidh e01h ? (4) e60h b4con e40h b2con e20h b0con e00h ? (4) table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f6585/8585/6680/8680 ds30491c-page 326 ? 2004 microchip technology inc. dffh ? (4) ddfh ? (4) dbfh ? (4) d9fh ? (4) dfeh ? (4) ddeh ? (4) dbeh ? (4) d9eh ? (4) dfdh ? (4) dddh ? (4) dbdh ? (4) d9dh ? (4) dfch txbie ddch ? (4) dbch ? (4) d9ch ? (4) dfbh ? (4) ddbh ? (4) dbbh ? (4) d9bh ? (4) dfah bie0 ddah ? (4) dbah ? (4) d9ah ? (4) df9h ? (4) dd9h ? (4) db9h ? (4) d99h ? (4) df8h bsel0 dd8h sdflc db8h ? (4) d98h ? (4) df7h ? (4) dd7h ? (4) db7h ? (4) d97h ? (4) df6h ? (4) dd6h ? (4) db6h ? (4) d96h ? (4) df5h ? (4) dd5h rxfcon1 db5h ? (4) d95h ? (4) df4h ? (4) dd4h rxfcon0 db4h ? (4) d94h ? (4) df3h msel3 dd3h ? (4) db3h ? (4) d93h rxf15eidl df2h msel2 dd2h ? (4) db2h ? (4) d92h rxf15eidh df1h msel1 dd1h ? (4) db1h ? (4) d91h rxf15sidl df0h msel0 dd0h ? (4) db0h ? (4) d90h rxf15sidh defh ? (4) dcfh ? (4) dafh ? (4) d8fh ? (4) deeh ? (4) dceh ? (4) daeh ? (4) d8eh ? (4) dedh ? (4) dcdh ? (4) dadh ? (4) d8dh ? (4) dech ? (4) dcch ? (4) dach ? (4) d8ch ? (4) debh ? (4) dcbh ? (4) dabh ? (4) d8bh rxf14eidl deah ? (4) dcah ? (4) daah ? (4) d8ah rxf14eidh de9h ? (4) dc9h ? (4) da9h ? (4) d89h rxf14sidl de8h ? (4) dc8h ? (4) da8h ? (4) d88h rxf14sidh de7h rxfbcon7 dc7h ? (4) da7h ? (4) d87h rxf13eidl de6h rxfbcon6 dc6h ? (4) da6h ? (4) d86h rxf13eidh de5h rxfbcon5 dc5h ? (4) da5h ? (4) d85h rxf13sidl de4h rxfbcon4 dc4h ? (4) da4h ? (4) d84h rxf13sidh de3h rxfbcon3 dc3h ? (4) da3h ? (4) d83h rxf12eidl de2h rxfbcon2 dc2h ? (4) da2h ? (4) d82h rxf12eidh de1h rxfbcon1 dc1h ? (4) da1h ? (4) d81h rxf12sidl de0h rxfbcon0 dc0h ? (4) da0h ? (4) d80h rxf12sidh table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
? 2004 microchip technology inc. ds30491c-page 327 pic18f6585/8585/6680/8680 table 23-1: can controller register map (continued) address (1) name d7fh ? (4) d7eh ? (4) d7dh ? (4) d7ch ? (4) d7bh rxf11eidl d7ah rxf11eidh d79h rxf11sidl d78h rxf11sidh d77h rxf10eidl d76h rxf10eidh d75h rxf10sidl d74h rxf10sidh d73h rxf9eidl d72h rxf9eidh d71h rxf9sidl d70h rxf9sidh d6fh ? (4) d6eh ? (4) d6dh ? (4) d6ch ? (4) d6bh rxf8eidl d6ah rxf8eidh d69h rxf8sidl d68h rxf8sidh d67h rxf7eidl d66h rxf7eidh d65h rxf7sidl d64h rxf7sidh d63h rxf6eidl d62h rxf6eidh d61h rxf6sidl d60h rxf6sidh note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f6585/8585/6680/8680 ds30491c-page 328 ? 2004 microchip technology inc. 23.3 can modes of operation the pic18f6585/8585/6680/8680 has six main modes of operation:  configuration mode  disable mode  normal operation mode  listen only mode  loopback mode  error recognition mode all modes, except error recognition, are requested by setting the reqop bits (cancon<7:5>); error recog- nition is requested through the rxm bits of the receive buffer register(s). entry into a mode is acknowledged by monitoring the opmode bits. when changing modes, the mode will not actually change until all pending message transmissions are complete. because of this, the user must verify that the device has actually changed into the requested mode before further operations are executed. 23.3.1 configuration mode the can module must be initialized before the activation. this is only possible if the module is in the configuration mode. the configuration mode is requested by setting the reqop2 bit. only when the status bit, opmode2, has a high level can the initial- ization be performed. once in configuration mode, registers such as baud rate control, acceptance mask/ filter and ecan mode selection can be modified. a new ecan mode selection does not take into effect until configuration mode is exited. the module is activated by setting the reqop control bits to zero. the module will protect the user from accidentally violating the can protocol through programming errors. all registers which control the configuration of the module can not be modified while the module is online. the can module will not be allowed to enter the configuration mode while a transmission or reception is taking place. the can module will also not be allowed, if the canrx pin is low (i.e., the can bus is busy). the can module waits for 11 recessive bits on the can bus (bus idle condition) before switching to configuration mode. the configuration mode serves as a lock to protect the following registers:  configuration registers  functional mode selection registers  bit timing registers  identifier acceptance filter registers  identifier acceptance mask registers  filter and mask control registers  mask selection registers in the configuration mode, the module will not transmit or receive. the error counters are cleared and the inter- rupt flags remain unchanged. the programmer will have access to configuration registers that are access restricted in other modes. 23.3.2 disable mode in disable mode, the module will not transmit or receive. the module has the ability to set the wakif bit due to bus activity; however, any pending interrupts will remain and the error counters will retain their value. if reqop<2:0> is set to ? 001 ?, the module will enter the module disable mode. this mode is similar to disabling other peripheral modules by turning off the module enables. this causes the module internal clock to stop unless the module is active (i.e., receiving or transmit- ting a message). if the module is active, the module will wait for 11 recessive bits on the can bus, detect that condition as an idle bus, then accept the module disable command. opmode<2:0> = 001 indicates whether the module successfully went into module disable mode. the wakie interrupt is the only module interrupt that is still active in the module disable mode. if wake-up from can bus activity is required, the can module must be put into disable mode before putting the core to sleep. if the wakdis is cleared and wakie is set, the proces- sor will receive an interrupt whenever the module detects recessive to dominant transition. on wake-up, the module will automatically be set to the previous mode of operation. for example, if the module was switched from normal to disable mode on bus activity wake-up, the module will automatically enter into normal mode and the first message that caused the module to wake-up is lost. the module will not gener- ate any error frame. firmware logic must detect this condition and make sure that retransmission is requested. if the processor receives a wake-up inter- rupt while it is sleeping, more than one message may get lost. the actual number of messages lost would depend on the processor oscillator start-up time and incoming message bit rate. the i/o pins will revert to normal i/o function when the module is in the module disable mode. note: can module must be put in disable or configuration mode prior to putting the processor to sleep. failure to do that may put the can module in indeterminate state.
? 2004 microchip technology inc. ds30491c-page 329 pic18f6585/8585/6680/8680 23.3.3 normal mode this is the standard operating mode of the pic18f6585/8585/6680/8680 devices. in this mode, the device actively monitors all bus messages and gen- erates acknowledge bits, error frames, etc. this is also the only mode in which the pic18f6585/8585/6680/ 8680 devices will transmit messages over the can bus. 23.3.4 listen only mode listen only mode provides a means for the pic18f6585/8585/6680/8680 devices to receive all messages, including messages with errors. this mode can be used for bus monitor applications or for detecting the baud rate in ?hot plugging? situations. for auto-baud detection, it is necessary that there are at least two other nodes which are communicating with each other. the baud rate can be detected empirically by testing different values until valid messages are received. the listen only mode is a silent mode, meaning no messages will be transmitted while in this state, including error flags or acknowledge signals. the filters and masks can be used to allow only particular messages to be loaded into the receive registers, or the filter masks can be set to all zeros to allow a message with any identifier to pass. the error counters are reset and deactivated in this state. the listen only mode is activated by setting the mode request bits in the cancon register. 23.3.5 loopback mode this mode will allow internal transmission of messages from the transmit buffers to the receive buffers without actually transmitting messages on the can bus. this mode can be used in system development and testing. in this mode, the ack bit is ignored and the device will allow incoming messages from itself, just as if they were coming from another node. the loopback mode is a silent mode, meaning no messages will be trans- mitted while in this state, including error flags or acknowledge signals. the cantx pin will revert to port i/o while the device is in this mode. the filters and masks can be used to allow only particular messages to be loaded into the receive registers. the masks can be set to all zeros to provide a mode that accepts all messages. the loopback mode is activated by setting the mode request bits in the cancon register. 23.3.6 error recognition mode the module can be set to ignore all errors and receive any message. in functional mode 0, the error recogni- tion mode is activated by setting the rxm<1:0> bits in the rxbncon registers to ? 11 ?. in this mode, the data which is in the message assembly buffer until the error time, is copied in the receive buffer and can be read via the cpu interface. 23.4 can module functional modes in addition to can modes of operation, the ecan module offers a total of three functional modes. each of these modes are identified as mode 0, mode 1 and mode 2. 23.4.1 mode 0 ? legacy mode mode 0 is designed to be fully compatible with can modules used in pic18cxx8 and pic18fxx8 devices. this is the default mode of operation on all reset conditions. as a result, module code written for the pic18xx8 can module may be used on the ecan module without any code changes. the following is the list of resources available in mode 0:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  two acceptance masks, one for each receive buffer: rxm0, rxm1  six acceptance filters, 2 for rxb0 and 4 for rxb1: rxf0, rxf1, rxf2, rxf3, rxf4, rxf5 23.4.2 mode 1 ? enhanced legacy mode mode 1 is similar to mode 0, with the exception that more resources are available in mode 1. there are 16 acceptance filters and two acceptance mask regis- ters. acceptance filter 15 can be used as either an acceptance filter or an acceptance mask register. in addition to three transmit and two receive buffers, there are six more message buffers. one or more of these additional buffers can be programmed as transmit or receive buffers. these additional buffers can also be programmed to automatically handle rtr messages. fourteen of 16 acceptance filter registers can be dynamically associated to any receive buffer and acceptance mask register. this capability can be used to associate more than one filter to any one buffer.
pic18f6585/8585/6680/8680 ds30491c-page 330 ? 2004 microchip technology inc. when a receive buffer is programmed to use standard identifier messages, part of the full acceptance filter register can be used as data byte filter. the length of data byte filter is programmable from 0 to 18 bits. this functionality simplifies implementation of high-level protocols, such as devicenet. the following is the list of resources available in mode 1:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  six buffers programmable as tx or rx: b0-b5  automatic rtr handling on b0-b5  sixteen dynamically assigned acceptance filters: rxf0-rxf15  two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15  programmable data filter on standard identifier messages: sdflc 23.4.3 mode 2 ? enhanced fifo mode in mode 2, two or more receive buffers are used to form the receive fifo (first in first out) buffer. there is no one-to-one relation between the receive buffer and acceptance filter registers. any filter that is enabled and linked to any fifo receive buffer can generate acceptance and cause fifo to be updated. fifo length is user programmable, from 2-8 buffers deep. fifo length is determined by the very first programmable buffer that is configured as a transmit buffer. for example, if buffer 2 (b2) is programmed as a transmit buffer, fifo consists of rxb0, rxb1, b0 and b1 ? creating a fifo length of 4. if all programma- ble buffers are configured as receive buffers, fifo will have the maximum length of 8. the following is the list of resources available in mode 2:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  six buffers programmable as tx or rx; receive buffers form fifo: b0-b5  automatic rtr handling on b0-b5  sixteen acceptance filters: rxf0-rxf15  two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15  programmable data filter on standard identifier messages: sdflc, useful for devicenet protocol 23.5 can message buffers 23.5.1 dedicated transmit buffers the pic18f6585/8585/6680/8680 devices implement three dedicated transmit buffers ? txb0, txb1 and txb2. each of these buffers occupies 14 bytes of sram and are mapped into the sfr memory map. these are the only transmit buffers available in mode 0. mode 1 and 2 may access these and other additional buffers. each transmit buffer contains one control register (txbncon), four identifier registers (txbnsidl, txbnsidh, txbneidl, txbneidh), one data length count register (txbndlc) and eight data byte registers (txbndm). 23.5.2 dedicated receive buffers the pic18f6585/8585/6680/8680 devices implement two dedicated receive buffers ? rxb0 and rxb1. each of these buffers occupies 14 bytes of sram and are mapped into sfr memory map. these are the only receive buffers available in mode 0. mode 1 and 2 may access these and other additional buffers. each receive buffer contains one control register (rxbncon), four identifier registers (rxbnsidl, rxbnsidh, rxbneidl, rxbneidh), one data length count register (rxbndlc) and eight data byte registers (rxbndm). there is also a separate message assembly buffer (mab) which acts as an additional receive buffer. mab is always committed to receiving the next message from the bus and is not directly accessible to user firm- ware. the mab assembles all incoming messages one by one. a message is transferred to appropriate receive buffers only if the corresponding acceptance filter criteria is met.
? 2004 microchip technology inc. ds30491c-page 331 pic18f6585/8585/6680/8680 23.5.3 programmable transmit/ receive buffers the ecan module implements six new buffers: b0-b5. these buffers are individually programmable as either transmit or receive buffers. these buffers are available only in mode 1 and 2. as with dedicated transmit and receive buffers, each of these programmable buffers occupies 14 bytes of sram and are mapped into sfr memory map. each buffer contains one control register (bncon), four identifier registers (bnsidl, bnsidh, bneidl, bneidh), one data length count register (bndlc) and eight data byte registers (bndm). each of these registers contains two sets of control bits. depending on whether the buffer is configured as transmit or receive, one would use the corresponding control bit set. by default, all buffers are configured as receive buffers. each buffer can be individually configured as transmit or receive buffers by setting the corresponding txenn bit in the bsel0 register. when configured as transmit buffers, user firmware may access transmit buffers in any order similar to accessing dedicated transmit buffers. in receive config- uration, with mode 1 enabled, user firmware may also access receive buffers in any order required. but in mode 2, all receive buffers are combined to form a sin- gle fifo. actual fifo length is programmable by user firmware. access to fifo must be done through the fifo pointer bits (fp<4:0>) in the cancon register. it must be noted that there is no hardware protection against out of order fifo reads. 23.5.4 programmable auto-rtr buffers in mode 1 and 2, any of six programmable transmit/ receive buffers may be programmed to automatically respond to predefined rtr messages without user firmware intervention. automatic rtr handling is enabled by setting the txnen bit in the bsel0 register and the rtren bit in the bncon register. after this setup, when an rtr request is received, the txreq bit is automatically set and current buffer content is automatically queued for transmission as a rtr response. as with all transmit buffers, once the txreq bit is set, buffer registers become read-only and any writes to them will be ignored. the following outlines the steps required to automatically handle rtr messages: 1. set buffer to transmit mode by setting txnen bit to ? 1 ? in bsel0 register. 2. at least one acceptance filter must be associ- ated with this buffer and preloaded with expected rtr identifier. 3. bit rtren in bncon register must be set to ? 1 ?. 4. buffer must be preloaded with the data to be sent as a rtr response. normally, user firmware will keep buffer data registers up to date. if firmware attempts to update buffer while an automatic rtr response is in process of transmission, all writes to buffers are ignored. 23.6 can message transmission 23.6.1 initiating transmission for the mcu to have write access to the message buffer, the txreq bit must be clear, indicating that the message buffer is clear of any pending message to be transmitted. at a minimum, the sidh, sidl, and dlc registers must be loaded. if data bytes are present in the message, the data registers must also be loaded. if the message is to use extended identifiers, the eidh:eidl registers must also be loaded and the exide bit set. to initiate message transmission, the txreq bit must be set for each buffer to be transmitted. when txreq is set, the txabt, txlarb and txerr bits will be cleared. to successfully complete the transmission, there must be at least one node with matching baud rate on the network. setting the txreq bit does not initiate a message transmission, it merely flags a message buffer as ready for transmission. transmission will start when the device detects that the bus is available. the device will then begin transmission of the highest priority message that is ready. when the transmission has completed successfully, the txreq bit will be cleared, the txbnif bit will be set, and an interrupt will be generated if the txbnie bit is set. if the message transmission fails, the txreq will remain set, indicating that the message is still pending for transmission and one of the following condition flags will be set. if the message started to transmit but encountered an error condition, the txerr and the irxif bits will be set and an interrupt will be generated. if the message lost arbitration, the txlarb bit will be set.
pic18f6585/8585/6680/8680 ds30491c-page 332 ? 2004 microchip technology inc. 23.6.2 aborting transmission the mcu can request to abort a message by clearing the txreq bit associated with the corresponding mes- sage buffer (txbncon<3> or bncon<3>). setting the abat bit (cancon<4>) will request an abort of all pending messages. if the message has not yet started transmission or if the message started but is inter- rupted by loss of arbitration or an error, the abort will be processed. the abort is indicated when the module sets the txabt bit for the corresponding buffer (txbncon<6> or bncon<6>). if the message has started to transmit, it will attempt to transmit the current message fully. if the current message is transmitted fully and is not lost to arbitration or an error, the txabt bit will not be set because the message was transmit- ted successfully. likewise, if a message is being transmitted during an abort request and the message is lost to arbitration or an error, the message will not be retransmitted and the txabt bit will be set, indicating that the message was successfully aborted. once an abort is requested by setting abat or txabt bits, it cannot be cleared to cancel the abort request. only can module hardware or a por condition can clear it. 23.6.3 transmit priority transmit priority is a prioritization within the pic18f6585/8585/6680/8680 devices of the pending transmittable messages. this is independent from and not related to any prioritization implicit in the message arbitration scheme built into the can protocol. prior to sending the sof, the priority of all buffers that are queued for transmission is compared. the transmit buffer with the highest priority will be sent first. if more than one buffer has the same priority setting, the mes- sage is transmitted in the order of txb2, txb1, txb0, b5, b4, b3, b2, b1, b0. there are four levels of transmit priority. if txp bits for a particular message buffer are set to ? 11 ?, that buffer has the highest possible priority. if txp bits for a particular message buffer are ? 00 ?, that buffer has the lowest possible priority. figure 23-2: transmit buffers txreq txb0 txabt txlarb txerr txb0if message message queue control transmit byte sequencer txreq txb1 txabt txlarb txerr txb1if message txreq txb2 txabt txlarb txerr txb2if message message txb2if txreq txabt txlarb txerr txb3-txb8
? 2004 microchip technology inc. ds30491c-page 333 pic18f6585/8585/6680/8680 23.7 message reception 23.7.1 receiving a message of all receive buffers, the mab is always committed to receiving the next message from the bus. the mcu can access one buffer while the other buffer is available for message reception, or holding a previously received message. when a message is moved into either of the receive buffers, the associated rxful bit is set. this bit must be cleared by the mcu when it has completed process- ing the message in the buffer in order to allow a new message to be received into the buffer. this bit provides a positive lockout to ensure that the firmware has finished with the message before the module attempts to load a new message into the receive buffer. if the receive interrupt is enabled, an interrupt will be generated to indicate that a valid message has been received. once a message is loaded into any matching buffer, user firmware may determine exactly what filter caused this reception by checking the filter hit bits in the rxbncon or bncon registers. in mode 0, filhit<3:0> of rxbncon serve as filter hit bits. in mode 1 and 2, filhit<4:0> of bncon serve as filter hit bits. the same registers also indicate w hether the current message is rtr frame or not. a received message is considered a standard identifier message if the exid bit in rxbnsidl or the bnsidl register is cleared. conversely, a set exid bit indicates an extended identifier message. if the received message is a standard identifier message, user firmware needs to read the sidl and sidh registers. in the case of an extended identifier message, firmware should read the sidl, sidh, eidl and eidh registers. if the rxbndlc or bndlc register contain non-zero data count, user firmware should also read the corresponding number of data bytes by accessing the rxbndm or bndm registers. when a received message is rtr and if the current buffer is not configured for automatic rtr handling, user firmware must take appropriate action and respond manually. each receive buffer contains rxm bits to set special receive modes. in mode 0, rxm<1:0> bits in rxbncon define a total of four receive modes. in mode 1 and 2, rxm1 bit in combination with the exid mask and filter bit define the same four receive modes. normally, these bits are set to ? 00 ? to enable reception of all valid messages as determined by the appropriate acceptance filters. in this case, the deter- mination of whether or not to receive standard or extended messages is determined by the exide bit in the acceptance filter register. in mode 0, if the rxm bits are set to ? 01 ? or ? 10 ?, the receiver will accept only messages with standard or extended identifiers, respectively. if an acceptance filter has the exide bit set such that it does not correspond with the rxm mode, that acceptance filter is rendered useless. in mode 1 and 2, setting exid in the sidl mask register will ensure that only standard or extended identifiers are received. these two modes of rxm bits can be used in systems where it is known that only standard or extended messages will be on the bus. if the rxm bits are set to ? 11 ? (rxm1 = 1 in mode 1 and 2), the buffer will receive all messages regardless of the values of the acceptance filters. also, if a message has an error before the end of frame, that portion of the message assembled in the mab before the error frame, will be loaded into the buffer. this mode may serve as a valu- able debugging tool for a given can network. it should not be used in an actual system environment as the actual system will always have some bus errors and all nodes on the bus are expected to ignore them. in mode 1 and 2, when a programmable buffer is configured as a transmit buffer and one or more accep- tance filters are associated with it, all incoming mes- sages matching this acceptance filter criteria will be discarded. to avoid this scenario, user firmware must make sure that there are no acceptance filters associ- ated with a buffer configured as a transmit buffer. 23.7.2 receive priority when in mode 0, rxb0 is the higher priority buffer and has two message acceptance filters associated with it. rxb1 is the lower priority buffer and has four acceptance filters associated with it. the lower number of acceptance filters makes the match on rxb0 more restrictive and implies a higher priority for that buffer. additionally, the rxb0con register can be configured such that if rxb0 contains a valid message and another valid message is received, an overflow error will not occur and the new message will be moved into rxb1 regardless of the acceptance criteria of rxb1. there are also two programmable acceptance filter masks available, one for each receive buffer (see section 4.5). note: the entire contents of the mab are moved into the receive buffer once a message is accepted. this means that regardless of the type of identifier (standard or extended) and the number of data bytes received, the entire receive buffer is over- written with the mab contents. therefore, the contents of all registers in the buffer must be assumed to have been modified when any message is received.
pic18f6585/8585/6680/8680 ds30491c-page 334 ? 2004 microchip technology inc. in mode 1 and 2, there are a total of 16 acceptance fil- ters available and each can be dynamically assigned to any of the receive buffers. a buffer with a lower number has higher priority. given this, if an incoming message matches with two or more receive buffer acceptance criteria, the buffer with the lower number will be loaded with that message. 23.7.3 enhanced fifo mode when configured for mode 2, two of the dedicated receive buffers, in combination with one or more pro- grammable transmit/receive buffers, are used to create a maximum of 8 buffers deep fifo (first in first out) buffer. in this mode, there is no direct correlation between filters and receive buffer registers. any filter that has been enabled can generate an acceptance. when a message has been accepted, it is stored in the next available receive buffer register and an internal write pointer is incremented. the fifo can be a maxi- mum of 8 buffers deep. the entire fifo must consist of contiguous receive buffers. the fifo head begins at rxb0 buffer and its tail spans toward b5. the maxi- mum length of the fifo is limited by the presence or absence of the first transmit buffer starting from b0. if a buffer is configured as a transmit buffer, the fifo length is reduced accordingly. for instance, if b3 is configured as transmit buffer, the actual fifo will con- sist of rxb0, rxb1, b0, b1 and b2, a total of 5 buffers. if b0 is configured as a transmit buffer, the fifo length will be 2. if none of the programmable buffers are con- figured as a transmit buffer, the fifo will be 8 buffers deep. a system that requires more transmit buffers should try to locate transmit buffers at the very end of b0-b5 buffers to maximize available fifo length. when a message is received in fifo mode, the inter- rupt flag code bits (eicode<4:0>) in the canstat register will have a value of ? 10000 ?, indicating the fifo has received a message. fifo pointer bits fp<3:0> in the cancon register point to the buffer that contains data not yet read. the fifo pointer bits, in this sense, serve as the fifo read pointer. the user should use fp bits and read corresponding buffer data. when receive data is no longer needed, the rxful bit in the current buffer must be cleared, causing fp<3:0> to be updated by the module. to determine whether fifo is empty or not, the user may use fp<3:0> bits to access rxful bit in the cur- rent buffer. if rxful is cleared, the fifo is considered to be empty. if it is set, the fifo may contain one or more messages. in mode 2, the module also provides a bit called fifo high water mark (fifowm) in the ecancon register. this bit can be used to cause an interrupt whenever the fifo contains only one or four empty buffers. the fifo high water mark interrupt can serve as an early warning to a full fifo condition. 23.7.4 time-stamping the can module can be programmed to generate a time-stamp for every message that is received. when enabled, the module generates a capture signal for ccp1, which in turn captures the value of either timer1 or timer3. this value can be used as the message time-stamp. to use the time-stamp capability, the cancap bit (ciocan<4>) must be set. this replaces the capture input for ccp1 with the signal generated from the can module. in addition, ccp1con<3:0> must be set to ? 0011 ? to enable the ccp special event trigger for can events. 23.8 message acceptance filters and masks the message acceptance filters and masks are used to determine if a message in the message assembly buffer should be loaded into any of the receive buffers. once a valid message has been received into the mab, the identifier fields of the message are compared to the filter values. if there is a match, that message will be loaded into the appropriate receive buffer. the filter masks are used to determine which bits in the identifier are examined with the filters. a truth table is shown below in table 23-2 that indicates how each bit in the identifier is compared to the masks and filters to deter- mine if a message should be loaded into a receive buffer. the mask essentially determines which bits to apply the acceptance filters to. if any mask bit is set to a zero, then that bit will automatically be accepted regardless of the filter bit. table 23-2: filter/mask truth table in mode 0, acceptance filters rxf0 and rxf1 and filter mask rxm0 are associated with rxb0. filters rxf2, rxf3, rxf4 and rxf5 and mask rxm1 are associated with rxb1. mask bit n filter bit n message identifier bit n001 accept or reject bit n 0x x accept 10 0 accept 10 1 reject 11 0 reject 11 1 accept legend: x = don?t care
? 2004 microchip technology inc. ds30491c-page 335 pic18f6585/8585/6680/8680 in mode 1 and 2, there are an additional 10 acceptance filters, rxf6-rxf15, creating a total of 16 available filters. rxf15 can be used either as an acceptance filter or acceptance mask register. each of these acceptance filters can be individually enabled or disabled by setting or clearing rxfenn bit in the rxfconn register. any of these 16 acceptance filters can be dynamically associated with any of the receive buffers. actual association is made by setting appropri- ate bits in the rxfbconn register. each rxfbconn register contains a nibble for each filter. this nibble can be used to associate a specific filter to any of available receive buffers. user firmware may associate more than one filter to any one specific receive buffer. in addition to dynamic filter to buffer association, in mode 1 and 2, each filter can also be dynamically asso- ciated to available acceptance mask registers. filn_m bits in the mseln register can be used to link a specific acceptance filter to an acceptance mask register. as with filter to buffer association, one can also associate more than one mask to a specific acceptance filter. when a filter matches and a message is loaded into the receive buffer, the filter number that enabled the message reception is loaded into the filhit bit(s). in mode 0 for rxb1, the rxb1con register contains the filhit<2:0> bits. they are coded as follows:  101 = acceptance filter 5 (rxf5)  100 = acceptance filter 4 (rxf4)  011 = acceptance filter 3 (rxf3)  010 = acceptance filter 2 (rxf2)  001 = acceptance filter 1 (rxf1)  000 = acceptance filter 0 (rxf0) the coding of the rxb0dben bit enables these three bits to be used similarly to the filhit bits and to distin- guish a hit on filter rxf0 and rxf1, in either rxb0 or after a rollover into rxb1.  111 = acceptance filter 1 (rxf1)  110 = acceptance filter 0 (rxf0)  001 = acceptance filter 1 (rxf1)  000 = acceptance filter 0 if the rxb0dben bit is clear, there are six codes cor- responding to the six filters. if the rxb0dben bit is set, there are six codes corresponding to the six filters plus two additional codes corresponding to rxf0 and rxf1 filters that rollover into rxb1. in mode 1 and 2, each buffer control register contains 5 bits of filter hit bits filhit<4:0>. a binary value of ? 0 ? indicates a hit from rxf0 and 15 indicates rxf15. if more than one acceptance filter matches, the filhit bits will encode the binary value of the lowest numbered filter that matched. in other words, if filter rxf2 and filter rxf4 match, filhit will be loaded with the value for rxf2. this essentially prioritizes the acceptance filters with a lower number filter having higher priority. messages are compared to filters in ascending order of filter number. the mask and filter registers can only be modified when the pic18f6585/8585/6680/8680 devices are in configuration mode. figure 23-3: message acceptance mask and filter operation note: ? 000 ? and ? 001 ? can only occur if the rxb0dben bit is set in the rxb0con register, allowing rxb0 messages to rollover into rxb1. acceptance filter register acceptance mask register rxrqst message assembly buffer rxfn 0 rxfn 1 rxfn n rxmn 0 rxmn 1 rxmn n identifier
pic18f6585/8585/6680/8680 ds30491c-page 336 ? 2004 microchip technology inc. 23.9 baud rate setting all nodes on a given can bus must have the same nominal bit rate. the can protocol uses non-return- to-zero (nrz) coding which does not encode a clock within the data stream. therefore, the receive clock must be recovered by the receiving nodes and synchronized to the transmitter?s clock. as oscillators and transmission time may vary from node to node, the receiver must have some type of phase lock loop (pll) synchronized to data transmis- sion edges to synchronize and maintain the receiver clock. since the data is nrz coded, it is necessary to include bit stuffing to ensure that an edge occurs at least every six bit times to maintain the digital phase lock loop (dpll) synchronization. the bit timing of the pic18f6585/8585/6680/8680 is implemented using a dpll that is configured to syn- chronize to the incoming data and provides the nominal timing for the transmitted data. the dpll breaks each bit time into multiple segments made up of minimal periods of time called the time quanta (t q ). bus timing functions executed within the bit time frame, such as synchronization to the local oscillator, network transmission delay compensation, and sample point positioning, are defined by the programmable bit timing logic of the dpll. all devices on the can bus must use the same bit rate. however, all devices are not required to have the same master oscillator clock frequency. for the different clock frequencies of the individual devices, the bit rate has to be adjusted by appropriately setting the baud rate prescaler and number of time quanta in each segment. the nominal bit rate is the number of bits transmitted per second, assuming an ideal transmitter with an ideal oscillator, in the absence of resynchronization. the nominal bit rate is defined to be a maximum of 1 mb/s. the nominal bit time is defined as: equation 23-1: the nominal bit time can be thought of as being divided into separate, non-overlapping time segments. these segments (figure 23-4) include:  synchronization segment (sync_seg)  propagation time segment (prop_seg)  phase buffer segment 1 (phase_seg1)  phase buffer segment 2 (phase_seg2) the time segments (and thus the nominal bit time) are in turn made up of integer units of time called time quanta or t q (see figure 23-4). by definition, the nom- inal bit time is programmable from a minimum of 8 t q to a maximum of 25 t q . also by definition, the minimum nominal bit time is 1 s, corresponding to a maximum 1 mb/s rate. the actual duration is given by the relationship: equation 23-2: the time quantum is a fixed unit derived from the oscillator period. it is also defined by the programmable baud rate prescaler with integer values from 1 to 64 in addition to a fixed divide-by-two for clock generation. mathematically, this is: equation 23-3: where f osc is the clock frequency, t osc is the corre- sponding oscillator period, and brp is an integer (0 through 63) represented by the binary values of brgcon1<5:0>. figure 23-4: bit time partitioning t bit = 1/nominal bit rate nominal bit time = t q * (sync_seg + prop_seg + phase_seg1 + phase_seg2) t q ( s) = (2 * (brp+1))/f osc (mhz) or t q ( s) = (2 * (brp+1)) * t osc ( s) input sync propagation segment phase segment 1 phase segment 2 sample point t q nominal bit time bit time intervals signal segment
? 2004 microchip technology inc. ds30491c-page 337 pic18f6585/8585/6680/8680 23.9.1 time quanta as already mentioned, the time quanta is a fixed unit derived from the oscillator period and baud rate prescaler. its relationship to t bit and the nominal bit rate is shown in example 23-6. example 23-6: calculating t q , nominal bit rate and nominal bit time the frequencies of the oscillators in the different nodes must be coordinated in order to provide a system wide specified nominal bit time. this means that all oscilla- tors must have a t osc that is an integral divisor of t q . it should also be noted that although the number of t q is programmable from 4 to 25, the usable minimum is 8t q . a bit time of less than 8 t q in length is not guaranteed to operate correctly. 23.9.2 synchronization segment this part of the bit time is used to synchronize the various can nodes on the bus. the edge of the input signal is expected to occur during the sync segment. the duration is 1 t q . 23.9.3 propagation segment this part of the bit time is used to compensate for phys- ical delay times within the network. these delay times consist of the signal propagation time on the bus line and the internal delay time of the nodes. the length of the propagation segment can be programmed from 1t q to 8 t q by setting the prseg2:prseg0 bits. 23.9.4 phase buffer segments the phase buffer segments are used to optimally locate the sampling point of the received bit within the nominal bit time. the sampling point occurs between phase segment 1 and phase segment 2. these segments can be lengthened or shortened by the resynchronization process. the end of phase segment 1 determines the sampling point within a bit time. phase segment 1 is programmable from 1 t q to 8 t q in duration. phase segment 2 provides delay before the next transmitted data transition and is also programmable from 1 t q to 8 t q in duration. however, due to ipt requirements, the actual minimum length of phase segment 2 is 2 t q , or it may be defined to be equal to the greater of phase segment 1 or the information processing time (ipt). 23.9.5 sample point the sample point is the point of time at which the bus level is read and the value of the received bit is deter- mined. the sampling point occurs at the end of phase segment 1. if the bit timing is slow and contains many t q , it is possible to specify multiple sampling of the bus line at the sample point. the value of the received bit is determined to be the value of the majority decision of three values. the three samples are taken at the sam- ple point and twice before, with a time of t q /2 between each sample. 23.9.6 information processing time the information processing time (ipt) is the time segment starting at the sample point that is reserved for calculation of the subsequent bit level. the can specification defines this time to be less than or equal to 2 t q . the pic18f6585/8585/6680/8680 devices define this time to be 2 t q . thus, phase segment 2 must be at least 2 t q long. t q ( s) = (2 * (brp+1))/f osc (mhz) t bit ( s) = t q ( s) * number of t q per bit interval nominal bit rate (bits/s) = 1/t bit case 1: for f osc = 16 mhz, brp<5:0> = 00h and nominal bit time = 8 t q : t q = (2*1)/16 = 0.125 s (125 ns) t bit = 8 * 0.125 = 1 s (10 -6 s) nominal bit rate = 1/10 -6 = 10 6 bits/s (1 mb/s) case 2: for f osc = 20 mhz, brp<5:0> = 01h and nominal bit time = 8 t q : t q = (2*2)/20 = 0.2 s (200 ns) t bit = 8 * 0.2 = 1.6 s (1.6 * 10 -6 s) nominal bit rate = 1/1.6 * 10 -6 s = 625,000 bits/s (625 kb/s) case 3: for f osc = 25 mhz, brp<5:0> = 3fh and nominal bit time = 25 t q : t q = (2*64)/25 = 5.12 s t bit = 25 * 5.12 = 128 s (1.28 * 10 -4 s) nominal bit rate = 1/1.28 * 10 -4 = 7813 bits/s (7.8 kb/s)
pic18f6585/8585/6680/8680 ds30491c-page 338 ? 2004 microchip technology inc. 23.10 synchronization to compensate for phase shifts between the oscillator frequencies of each of the nodes on the bus, each can controller must be able to synchronize to the relevant signal edge of the incoming signal. when an edge in the transmitted data is detected, the logic will compare the location of the edge to the expected time (sync_seg). the circuit will then adjust the values of phase segment 1 and phase segment 2 as necessary. there are two mechanisms used for synchronization. 23.10.1 hard synchronization hard synchronization is only done when there is a recessive to dominant edge during a bus idle condition, indicating the start of a message. after hard synchroni- zation, the bit time counters are restarted with sync_seg. hard synchronization forces the edge which has occurred to lie within the synchronization segment of the restarted bit time. due to the rules of synchronization, if a hard synchronization occurs there will not be a resynchronization within that bit time. 23.10.2 resynchronization as a result of resynchronization, phase segment 1 may be lengthened or phase segment 2 may be short- ened. the amount of lengthening or shortening of the phase buffer segments has an upper bound given by the synchronization jump width (sjw). the value of the sjw will be added to phase segment 1 (see figure 23-5) or subtracted from phase segment 2 (see figure 23-6). the sjw is programmable between 1 t q and 4 t q . clocking information will only be derived from reces- sive to dominant transitions. the property that only a fixed maximum number of successive bits have the same value, ensures resynchronization to the bit stream during a frame. the phase error of an edge is given by the position of the edge relative to sync_seg, measured in t q . the phase error is defined in magnitude of t q as follows:  e = 0 if the edge lies within sync_seg.  e > 0 if the edge lies before the sample point.  e < 0 if the edge lies after the sample point of the previous bit. if the magnitude of the phase error is less than, or equal to the programmed value of the synchronization jump width, the effect of a resynchronization is the same as that of a hard synchronization. if the magnitude of the phase error is larger than the synchronization jump width, and if the phase error is positive, then phase segment 1 is lengthened by an amount equal to the synchronization jump width. if the magnitude of the phase error is larger than the resynchronization jump width, and if the phase error is negative, then phase segment 2 is shortened by an amount equal to the synchronization jump width. 23.10.3 synchronization rules  only one synchronization within one bit time is allowed.  an edge will be used for synchronization only if the value detected at the previous sample point (previously read bus value) differs from the bus value immediately after the edge.  all other recessive to dominant edges fulfilling rules 1 and 2 will be used for resynchronization, with the exception that a node transmitting a dominant bit will not perform a resynchronization as a result of a recessive to dominant edge with a positive phase error.
? 2004 microchip technology inc. ds30491c-page 339 pic18f6585/8585/6680/8680 figure 23-5: lengthening a bit period (adding sjw to phase segment 1) figure 23-6: shortening a bit period (subtracting sjw from phase segment 2) input sync prop segment phase segment 1 phase segment 2 sjw sample point t q signal nominal bit length actual bit length bit time segments sync prop segment phase segment 1 phase segment 2 sjw t q sample point nominal bit length actual bit length
pic18f6585/8585/6680/8680 ds30491c-page 340 ? 2004 microchip technology inc. 23.11 programming time segments some requirements for programming of the time segments:  prop_seg + phase_seg 1 phase_seg 2  phase_seg 2 sync jump width. for example, assume that a 125 khz can baud rate is desired, using 20 mhz for f osc . with a t osc of 50 ns, a baud rate prescaler value of 04h gives a t q of 500 ns. to obtain a nominal bit rate of 125 khz, the nominal bit time must be 8 s or 16 t q . using 1 t q for the sync_seg, 2 t q for the prop_seg and 7 t q for phase segment 1, would place the sample point at 10 t q after the transition. this leaves 6 t q for phase segment 2. by the rules above, the sync jump width could be the maximum of 4 t q . however, normally a large sjw is only necessary when the clock generation of the different nodes is inaccurate or unstable, such as using ceramic resonators. typically, an sjw of 1 is enough. 23.12 oscillator tolerance as a rule of thumb, the bit timing requirements allow ceramic resonators to be used in applications with transmission rates of up to 125 kbit/sec. for the full bus speed range of the can protocol, a quartz oscillator is required. a maximum node-to-node oscillator variation of 1.7% is allowed. 23.13 bit timing configuration registers the configuration registers (brgcon1, brgcon2, brgcon3) control the bit timing for the can bus interface. these registers can only be modified when the pic18f6585/8585/6680/8680 devices are in configuration mode. 23.13.1 brgcon1 the brp bits control the baud rate prescaler. the sjw<1:0> bits select the synchronization jump width in terms of multiples of t q . 23.13.2 brgcon2 the prseg bits set the length of the propagation seg- ment in terms of t q . the seg1ph bits set the length of phase segment 1 in t q . the sam bit controls how many times the rxcan pin is sampled. setting this bit to a ? 1 ? causes the bus to be sampled three times; twice at t q /2 before the sample point and once at the normal sample point (which is at the end of phase segment 1). the value of the bus is determined to be the value read during at least two of the samples. if the sam bit is set to a ? 0 ?, then the rxcan pin is sampled only once at the sample point. the seg2phts bit controls how the length of phase segment 2 is determined. if this bit is set to a ? 1 ?, then the length of phase segment 2 is determined by the seg2ph bits of brgcon3. if the seg2phts bit is set to a ? 0 ?, then the length of phase segment 2 is the greater of phase segment 1 and the information processing time (which is fixed at 2 t q for the pic18f6585/8585/6680/8680). 23.13.3 brgcon3 the phseg2<2:0> bits set the length (in t q ) of phase segment 2 if the seg2phts bit is set to a ? 1 ?. if the seg2phts bit is set to a ? 0 ?, then the phseg2<2:0> bits have no effect. 23.14 error detection the can protocol provides sophisticated error detection mechanisms. the following errors can be detected. 23.14.1 crc error with the cyclic redundancy check (crc), the trans- mitter calculates special check bits for the bit sequence, from the start of a frame until the end of the data field. this crc sequence is transmitted in the crc field. the receiving node also calculates the crc sequence using the same formula and performs a comparison to the received sequence. if a mismatch is detected, a crc error has occurred and an error frame is generated. the message is repeated.
? 2004 microchip technology inc. ds30491c-page 341 pic18f6585/8585/6680/8680 23.14.2 acknowledge error in the acknowledge field of a message, the transmitter checks if the acknowledge slot (which was sent out as a recessive bit) contains a dominant bit. if not, no other node has received the frame correctly. an acknowl- edge error has occurred; an error frame is generated and the message will have to be repeated. 23.14.3 form error if a node detects a dominant bit in one of the four segments, including end of frame, interframe space, acknowledge delimiter, or crc delimiter, then a form error has occurred and an error frame is generated. the message is repeated. 23.14.4 bit error a bit error occurs if a transmitter sends a dominant bit and detects a recessive bit, or if it sends a recessive bit and detects a dominant bit, when monitoring the actual bus level and comparing it to the just transmitted bit. in the case where the transmitter sends a recessive bit and a dominant bit is detected during the arbitration field and the acknowledge slot, no bit error is generated because normal arbitration is occurring. 23.14.5 stuff bit error lf between the start of frame and the crc delimiter, six consecutive bits with the same polarity are detected, the bit stuffing rule has been violated. a stuff bit error occurs and an error frame is generated. the message is repeated. 23.14.6 error states detected errors are made public to all other nodes via error frames. the transmission of the erroneous mes- sage is aborted and the frame is repeated as soon as possible. furthermore, each can node is in one of the three error states ?error-active?, ?error-passive? or ?bus- off? according to the value of the internal error counters. the error-active state is the usual state where the bus node can transmit messages and activate error frames (made of dominant bits) without any restrictions. in the error-passive state, messages and passive error frames (made of recessive bits) may be transmitted. the bus-off state makes it temporarily impossible for the station to participate in the bus communication. during this state, messages can neither be received nor transmitted. 23.14.7 error modes and error counters the pic18f6585/8585/6680/8680 devices contain two error counters: the receive error counter (rxerrcnt), and the transmit error counter (txerrcnt). the values of both counters can be read by the mcu. these counters are incremented or decremented in accordance with the can bus specification. the pic18f6585/8585/6680/8680 devices are error- active if both error counters are below the error-passive limit of 128. they are error-passive if at least one of the error counters equals or exceeds 128. they go to bus- off if the transmit error counter equals or exceeds the bus-off limit of 256. the devices remain in this state until the bus-off recovery sequence is received. the bus-off recovery sequence consists of 128 occurrences of 11 consecutive recessive bits (see figure 23-7). note that the can module, after going bus-off, will recover back to error-active without any intervention by the mcu if the bus remains idle for 128 x 11 bit times. if this is not desired, the error interrupt service routine should address this. the current error mode of the can module can be read by the mcu via the comstat register. additionally, there is an error state warning flag bit, ewarn, which is set if at least one of the error counters equals or exceeds the error warning limit of 96. ewarn is reset if both error counters are less than the error warning limit.
pic18f6585/8585/6680/8680 ds30491c-page 342 ? 2004 microchip technology inc. figure 23-7: error modes state diagram 23.15 can interrupts the module has several sources of interrupts. each of these interrupts can be individually enabled or dis- abled. the pir3 register contains interrupt flags. the pie3 register contains the enables for the 8 main inter- rupts. a special set of read-only bits in the canstat register, the icode bits, can be used in combination with a jump table for efficient handling of interrupts. all interrupts have one source with the exception of the error interrupt and buffer interrupts in mode 1 and 2. any of the error interrupt sources can set the error interrupt flag. the source of the error interrupt can be determined by reading the communication status register, comstat. in mode 1 and 2, there are two interrupt enable/disable and flag bits ? one for all transmit buffers and the other for all receive buffers. the interrupts can be broken up into two categories: receive and transmit interrupts. the receive related interrupts are:  receive interrupts  wake-up interrupt  receiver overrun interrupt  receiver warning interrupt  receiver error-passive interrupt the transmit related interrupts are:  transmit interrupts  transmitter warning interrupt  transmitter error-passive interrupt  bus-off interrupt 23.15.1 interrupt code bits to simplify the interrupt handling process in user firm- ware, the ecan module encodes a special set of bits. in mode 0, these bits are icode<2:0> in the canstat register. in mode 1 and 2, these bits are eicode<3:0> in the canstat register. interrupts are internally priori- tized such that the higher priority interrupts are assigned lower values. once the highest priority interrupt condi- tion has been cleared, the code for the next highest priority interrupt that is pending (if any) will be reflected by the icode bits. note that only those interrupt sources that have their associated interrupt enable bit set will be reflected in the icode bits. in mode 2, when a receive message interrupt occurs, eicode bits will always consist of ? 10000 ?. user firmware may use fifo pointer bits to actually access the next available buffer. bus - off error - active error - passive rxerrcnt < 127 or txerrcnt < 127 rxerrcnt > 127 or txerrcnt > 127 txerrcnt > 255 128 occurrences of 11 consecutive ?recessive? bits reset
? 2004 microchip technology inc. ds30491c-page 343 pic18f6585/8585/6680/8680 23.15.2 transmit interrupt when the transmit interrupt is enabled, an interrupt will be generated when the associated transmit buffer becomes empty and is ready to be loaded with a new message. in mode 0, there are separate interrupt enable/disable and flag bits for each of the three dedicated transmit buffers. the txbnif bit will be set to indicate the source of the interrupt. the interrupt is cleared by the mcu resetting the txbnif bit to a ? 0 ?. in mode 1 and 2, all transmit buffers share one interrupt enable/disable and flag bits. in mode 1 and 2, txbie in pie3 and txbif in pir3 indicate when a transmit buffer has completed transmission of its message. txbnif, txbnie and txbnip in pir3, pie3 and ipr3, respec- tively, are not used in mode 1 and 2. individual transmit buffer interrupts can be enabled or disabled by setting or clearing txbie and bnie register bits. when a shared interrupt occurs, user firmware must poll the txreq bit of all transmit buffers to detect the source of interrupt. 23.15.3 receive interrupt when the receive interrupt is enabled, an interrupt will be generated when a message has been successfully received and loaded into the associated receive buffer. this interrupt is activated immediately after receiving the end of frame (eof) field. in mode 0, the rxbnif bit is set to indicate the source of the interrupt. the interrupt is cleared by the mcu resetting the rxbnif bit to a ? 0 ?. in mode 1 and 2, all receive buffers share one interrupt. individual receive buffer interrupts can be controlled by the rxbnie and bien registers. in mode 1, when a shared receive interrupt occurs, user firmware must poll the rxful bit of each receive buffer to detect the source of interrupt. in mode 2, a receive interrupt indicates that the new message is loaded into fifo. fifo can be read by using fifo pointer bits, fp. in mode 2, the fifowmif bit indicates if the fifo high watermark is reached. the fifo high watermark is defined by the fifowm bit in the ecancon register. 23.15.4 message error interrupt when an error occurs during transmission or reception of a message, the message error flag, irxif, will be set and if the irxie bit is set, an interrupt will be generated. this is intended to be used to facilitate baud rate determination when used in conjunction with listen only mode. 23.15.5 bus activity wake-up interrupt when the pic18f6585/8585/6680/8680 devices are in sleep mode and the bus activity wake-up interrupt is enabled, an interrupt will be generated and the wakif bit will be set when activity is detected on the can bus. this interrupt causes the pic18f6585/8585/6680/ 8680 devices to exit sleep mode. the interrupt is reset by the mcu, clearing the wakif bit. 23.15.6 error interrupt when the error interrupt is enabled, an interrupt is generated if an overflow condition occurs or if the error state of the transmitter or receiver has changed. the error flags in comstat will indicate one of the following conditions. 23.15.6.1 receiver overflow an overflow condition occurs when the mab has assembled a valid received message (the message meets the criteria of the acceptance filters) and the receive buffer associated with the filter is not available for loading of a new message. the associated comstat.rxnovfl bit will be set to indicate the overflow condition. this bit must be cleared by the mcu. 23.15.6.2 receiver warning the receive error counter has reached the mcu warning limit of 96. 23.15.6.3 transmitter warning the transmit error counter has reached the mcu warning limit of 96. 23.15.6.4 receiver bus passive the receive error counter has exceeded the error- passive limit of 127 and the device has gone to error-passive state. 23.15.6.5 transmitter bus passive the transmit error counter has exceeded the error- passive limit of 127 and the device has gone to error-passive state. 23.15.6.6 bus-off the transmit error counter has exceeded 255 and the device has gone to bus-off state. 23.15.6.7 interrupt acknowledge interrupts are directly associated with one or more sta- tus flags in the pir register. interrupts are pending as long as one of the flags is set. once an interrupt flag is set by the device, the flag can not be reset by the microcontroller until the interrupt condition is removed.
pic18f6585/8585/6680/8680 ds30491c-page 344 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 345 pic18f6585/8585/6680/8680 24.0 special features of the cpu there are several features intended to maximize sys- tem reliability, minimize cost through elimination of external components, provide power saving operating modes and offer code protection. these are:  osc selection  reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor)  interrupts  watchdog timer (wdt)  sleep  code protection  id locations  in-circuit serial programming all pic18f6585/8585/6680/8680 devices have a watchdog timer which is permanently enabled via the configuration bits or software controlled. it runs off its own rc oscillator for added reliability. there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt) which pro- vides a fixed delay on power-up only, designed to keep the part in reset while the power supply stabilizes. with these two timers on-chip, most applications need no external reset circuitry. sleep mode is designed to offer a very low current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up, or through an interrupt. several oscillator options are also made available to allow the part to fit the application. the rc oscillator option saves system cost, while the lp crystal option saves power. a set of configuration bits is used to select various options. 24.1 configuration bits the configuration bits can be programmed (read as ? 0 ?) or left unprogrammed (read as ? 1 ?) to select various device configurations. these bits are mapped, starting at program memory location 300000h. the user will note that address 300000h is beyond the user program memory space. in fact, it belongs to the configuration memory space (300000h through 3fffffh) which can only be accessed using table reads and table writes. programming the configuration registers is done in a manner similar to programming the flash memory. the eecon1 register wr bit starts a self-timed write to the configuration register. in normal operation mode, a tblwt instruction with the tblptr pointed to the con- figuration register sets up the address and the data for the configuration register write. setting the wr bit starts a long write to the configuration register. the configuration registers are written a byte at a time. to write or erase a configuration cell, a tblwt instruction can write a ? 1 ? or a ? 0 ? into the cell.
pic18f6585/8585/6680/8680 ds30491c-page 346 ? 2004 microchip technology inc. table 24-1: configuration bits and device ids file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprogrammed value 300001h config1h ? ?oscsen ? fosc3 fosc2 fosc1 fosc0 --1- 1111 300002h config2l ? ? ? ? borv1 borv0 boden pwrten ---- 1111 300003h config2h ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten ---1 1111 300004h (1) config3l wait ? ? ? ? ?pm1pm0 1--- --11 300005h config3h mclre ? ? ? ? ?eccpmx (4) ccp2mx 1--- --11 300006h config4l debug ? ? ? ?lvp ?stvren 1--- -1-1 300008h config5l ? ? ? ?cp3 (2) cp2 cp1 cp0 ---- 1111 300009h config5h cpd cpb ? ? ? ? ? ? 11-- ---- 30000ah config6l ? ? ? ?wrt3 (2) wrt2 wrt1 wrt0 ---- 1111 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 111- ---- 30000ch config7l ? ? ? ?ebtr3 (2) ebtr2 ebtr1 ebtr0 ---- 1111 30000dh config7h ?ebtrb ? ? ? ? ? ? -1-- ---- 3ffffeh devid1 dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 (note 3) 3fffffh devid2 dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 0000 1010 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition. shaded cells are unimplemented, read as ? 0 ?. note 1: unimplemented in pic18f6x8x devices; maintain this bit set. 2: unimplemented in pic18fx585 devices; maintain this bit set. 3: see register 24-13 for devid1 values. 4: reserved in pic18f6x8x devices; maintain this bit set.
? 2004 microchip technology inc. ds30491c-page 347 pic18f6585/8585/6680/8680 register 24-1: config1h: configuration register 1 high (byte address 300001h) u-0 u-0 r/p-1 u-0 r/p-1 r/p-1 r/p-1 r/p-1 ? ? oscsen ? fosc3 fosc2 fosc1 fosc0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5 oscsen : oscillator system clock switch enable bit 1 = oscillator system clock switch option is disabled (main oscillator is source) 0 = timer1 oscillator system clock switch option is enabled (oscillator switching is enabled) bit 4 unimplemented: read as ? 0 ? bit 3-0 fosc3:fosc0 : oscillator selection bits 1111 = rc oscillator with osc2 configured as ra6 1110 = hs oscillator with sw enabled 4x pll 1101 = ec oscillator with osc2 configured as ra6 and sw enabled 4x pll 1100 = ec oscillator with osc2 configured as ra6 and hw enabled 4x pll 1011 = reserved; do not use 1010 = reserved; do not use 1001 = reserved; do not use 1000 = reserved; do not use 0111 = rc oscillator with osc2 configured as ra6 0110 = hs oscillator with hw enabled 4x pll 0101 = ec oscillator with osc2 configured as ra6 0100 = ec oscillator with osc2 configured as divide by 4 clock output 0011 = rc oscillator with osc2 configured as divide by 4 clock output 0010 = hs oscillator 0001 = xt oscillator 0000 = lp oscillator legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
pic18f6585/8585/6680/8680 ds30491c-page 348 ? 2004 microchip technology inc. register 24-2: config2l: configuration register 2 low (byte address 300002h) u-0 u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ? ? borv1 borv0 boren pwrten bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3-2 borv1:borv0: brown-out reset voltage bits 11 = v bor set to 2.0v 10 = v bor set to 2.7v 01 = v bor set to 4.2v 00 = v bor set to 4.5v bit 1 boren: brown-out reset enable bit 1 = brown-out reset enabled 0 = brown-out reset disabled bit 0 pwrten : power-up timer enable bit 1 = pwrt disabled 0 = pwrt enabled legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. ds30491c-page 349 pic18f6585/8585/6680/8680 register 24-3: config2h: configuration register 2 high (byte address 300003h) register 24-4: config3l: configuration register 3 low (byte address 300004h) (1) u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps3:wdtps0: watchdog timer postscaler select bits 1111 = 1:32768 1110 = 1:16384 1101 = 1:8192 1100 = 1:4096 1011 = 1:2048 1010 = 1:1024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1 bit 0 wdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled (control is placed on the swdten bit) legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state r/p-1 u-0 u-0 u-0 u-0 u-0 r/p-1 r/p-1 wait ? ? ? ? ?pm1pm0 bit 7 bit 0 bit 7 wait: external bus data wait enable bit 1 = wait selections unavailable for table reads and table writes 0 = wait selections for table reads and table writes are determined by wait1:wait0 bits (memcom<5:4>) bit 6-2 unimplemented: read as ? 0 ? bit 1-0 pm1:pm0: processor mode select bits 11 = microcontroller mode 10 = microprocessor mode 01 = microprocessor with boot block mode 00 = extended microcontroller mode note 1: this register is unimplemented for pic18f6x8x devices; maintain these bits set. legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
pic18f6585/8585/6680/8680 ds30491c-page 350 ? 2004 microchip technology inc. register 24-5: config3h: configuration register 3 high (byte address 300005h) register 24-6: config4l: configuration register 4 low (byte address 300006h) r/p-1 u-0 u-0 u-0 u-0 u-0 r/p-1 r/p-1 mclre ? ? ? ? ? eccpmx ccp2mx bit 7 bit 0 bit 7 mclre: mclr enable bit (1) 1 = mclr pin enabled, rg5 input pin disabled 0 = rg5 input enabled, mclr disabled bit 6-2 unimplemented: read as ? 0 ? bit 1 eccpmx: ccp1 pwm outputs p1b, p1c mux bit (pic18f8x8x devices only) (2) 1 = p1b, p1c are multiplexed with re6, re5 0 = p1b, p1c are multiplexed with rh7, rh6 bit 0 ccp2mx: ccp2 mux bit in microcontroller mode: 1 = ccp2 input/output is multiplexed with rc1 0 = ccp2 input/output is multiplexed with re7 in microprocessor, microprocessor with boot block and extended microcontroller modes (pic18f8x8x devices only): 1 = ccp2 input/output is multiplexed with rc1 0 = ccp2 input/output is multiplexed with rb3 note 1: if mclr is disabled, either disable low-voltage icsp or hold rb5/pgm low to ensure proper entry into icsp mode. 2: reserved for pic18f6x8x devices; maintain this bit set. legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state r/p-1 u-0 u-0 u-0 u-0 r/p-1 u-0 r/p-1 debug ? ? ? ?lvp ?stvren bit 7 bit 0 bit 7 debug : background debugger enable bit 1 = background debugger disabled. rb6 and rb7 configured as general purpose i/o pins. 0 = background debugger enabled. rb6 and rb7 are dedicated to in-circuit debug. bit 6-3 unimplemented: read as ? 0 ? bit 2 lvp: low-voltage icsp enable bit 1 = low-voltage icsp enabled 0 = low-voltage icsp disabled bit 1 unimplemented: read as ? 0 ? bit 0 stvren: stack full/underflow reset enable bit 1 = stack full/underflow will cause reset 0 = stack full/underflow will not cause reset legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. ds30491c-page 351 pic18f6585/8585/6680/8680 register 24-7: config5l: configuration register 5 low (byte address 300008h) register 24-8: config5h: configuration register 5 high (byte address 300009h) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ?cp3 (1) cp2 cp1 cp0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 cp3: code protection bit (1) 1 = block 3 (00c000-00ffffh) not code-protected 0 = block 3 (00c000-00ffffh) code-protected note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 cp2: code protection bit 1 = block 2 (008000-00bfffh) not code-protected 0 = block 2 (008000-00bfffh) code-protected bit 1 cp1: code protection bit 1 = block 1 (004000-007fffh) not code-protected 0 = block 1 (004000-007fffh) code-protected bit 0 cp0: code protection bit 1 = block 0 (000800-003fffh) not code-protected 0 = block 0 (000800-003fffh) code-protected legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state r/c-1 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 cpd cpb ? ? ? ? ? ? bit 7 bit 0 bit 7 cpd: data eeprom code protection bit 1 = data eeprom not code-protected 0 = data eeprom code-protected bit 6 cpb: boot block code protection bit 1 = boot block (000000-0007ffh) not code-protected 0 = boot block (000000-0007ffh) code-protected bit 5-0 unimplemented: read as ? 0 ? legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
pic18f6585/8585/6680/8680 ds30491c-page 352 ? 2004 microchip technology inc. register 24-9: config6l: configuration register 6 low (byte address 30000ah) register 24-10: config6h: configuration register 6 high (byte address 30000bh) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ?wrt3 (1) wrt2 wrt1 wrt0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 wrt3: write protection bit (1) 1 = block 3 (00c000-00ffffh) not write-protected 0 = block 3 (00c000-00ffffh) write-protected note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 wrt2: write protection bit 1 = block 2 (008000-00bfffh) not write-protected 0 = block 2 (008000-00bfffh) write-protected bit 1 wrt1: write protection bit 1 = block 1 (004000-007fffh) not write-protected 0 = block 1 (004000-007fffh) write-protected bit 0 wr0: write protection bit 1 = block 0 (000800-003fffh) not write-protected 0 = block 0 (000800-003fffh) write-protected legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state r/c-1 r/c-1 r/c-1 u-0 u-0 u-0 u-0 u-0 wrtd wrtb wrtc ? ? ? ? ? bit 7 bit 0 bit 7 wrtd: data eeprom write protection bit 1 = data eeprom not write-protected 0 = data eeprom write-protected bit 6 wrtb: boot block write protection bit 1 = boot block (000000-0007ffh) not write-protected 0 = boot block (000000-0007ffh) write-protected bit 5 wrtc: configuration register write protection bit 1 = configuration registers (300000-3000ffh) not write-protected 0 = configuration registers (300000-3000ffh) write-protected bit 4-0 unimplemented: read as ? 0 ? legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. ds30491c-page 353 pic18f6585/8585/6680/8680 register 24-11: config7l: configuration register 7 low (byte address 30000ch) register 24-12: config7h: configuration register 7 high (byte address 30000dh) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ? ebtr3 (1) ebtr2 ebtr1 ebtr0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 ebtr3: table read protection bit (1) 1 = block 3 (00c000-00ffffh) not protected from table reads executed in other blocks 0 = block 3 (00c000-00ffffh) protected from table reads executed in other blocks note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 ebtr2: table read protection bit 1 = block 2 (008000-00bfffh) not protected from table reads executed in other blocks 0 = block 2 (008000-00bfffh) protected from table reads executed in other blocks bit 1 ebtr1: table read protection bit 1 = block 1 (004000-007fffh) not protected from table reads executed in other blocks 0 = block 1 (004000-007fffh) protected from table reads executed in other blocks bit 0 ebtr0: table read protection bit 1 = block 0 (000800-003fffh) not protected from table reads executed in other blocks 0 = block 0 (000800-003fffh) protected from table reads executed in other blocks legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state u-0 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 ? ebtrb ? ? ? ? ? ? bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 ebtrb: boot block table read protection bit 1 = boot block (000000-0007ffh) not protected from table reads executed in other blocks 0 = boot block (000000-0007ffh) protected from table reads executed in other blocks bit 5-0 unimplemented: read as ? 0 ? legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
pic18f6585/8585/6680/8680 ds30491c-page 354 ? 2004 microchip technology inc. register 24-13: device id register 1 for pic18fxx8x devices (address 3ffffeh) register 24-14: device id register 2 for pic18fxx8x devices (address 3fffffh) rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 bit 7-5 dev2:dev0: device id bits 000 = pic18f8680 001 = pic18f6680 010 = pic18f8585 011 = pic18f6585 bit 4-0 rev4:rev0: revision id bits these bits are used to indicate the device revision. legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state r-0 r-0 r-0 r-0 r-1 r-0 r-1 r-0 dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 bit 7 bit 0 bit 7-0 dev10:dev3: device id bits these bits are used with the dev2:dev0 bits in the device id register 1 to identify the part number. 0000 1010 = pic18f6585/8585/6680/8680 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. ds30491c-page 355 pic18f6585/8585/6680/8680 24.2 watchdog timer (wdt) the watchdog timer is a free-running, on-chip rc oscillator which does not require any external compo- nents. this rc oscillator is separate from the rc oscillator of the osc1/clki pin. that means that the wdt will run even if the clock on the osc1/clki and osc2/clko/ra6 pins of the device has been stopped, for example, by execution of a sleep instruction. during normal operation, a wdt time-out generates a device reset (watchdog timer reset). if the device is in sleep mode, a wdt time-out causes the device to wake-up and continue with normal operation (watch- dog timer wake-up). the to bit in the rcon register will be cleared upon a wdt time-out. the watchdog timer is enabled/disabled by a device configuration bit. if the wdt is enabled, software execution may not disable this function. when the wdten configuration bit is cleared, the swdten bit enables/disables the operation of the wdt. the wdt time-out period values may be found in section 27.0 ?electrical characteristics? under parameter #31. values for the wdt postscaler may be assigned using the configuration bits. 24.2.1 control register register 24-15 shows the wdtcon register. this is a readable and writable register which contains a control bit that allows software to override the wdt enable configuration bit, only when the configuration bit has disabled the wdt. register 24-15: wdtcon register note 1: the clrwdt and sleep instructions clear the wdt and the postscaler if assigned to the wdt and prevent it from timing out and generating a device reset condition. 2: when a clrwdt instruction is executed and the postscaler is assigned to the wdt, the postscaler count will be cleared but the postscaler assignment is not changed. u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?swdten bit 7 bit 0 bit 7-1 unimplemented : read as ? 0 ? bit 0 swdten: software controlled watchdog timer enable bit 1 = watchdog timer is on 0 = watchdog timer is turned off if the wdten conf iguration bit in the configuration register = 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f6585/8585/6680/8680 ds30491c-page 356 ? 2004 microchip technology inc. 24.2.2 wdt postscaler the wdt has a postscaler that can extend the wdt reset period. the postscaler is selected at the time of the device programming by the value written to the config2h configuration register. figure 24-1: watchdog timer block diagram table 24-2: summary of watchdog timer registers postscaler wdt timer wdten 16-to-1 mux wdtps3:wdtps0 wdt time-out 16 swdten bit configuration bit note: wdps3:wdps0 are bits in register config2h. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 config2h ? ? ? wdtps3 wdtps2 wdtps2 wdtps0 wdten rcon ipen ? ? ri to pd por bor wdtcon ? ? ? ? ? ? ?swdten legend: shaded cells are not used by the watchdog timer.
? 2004 microchip technology inc. ds30491c-page 357 pic18f6585/8585/6680/8680 24.3 power-down mode (sleep) power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit (rcon<3>) is cleared, the to (rcon<4>) bit is set and the oscillator driver is turned off. the i/o ports maintain the status they had before the sleep instruction was executed (driving high, low, or high-impedance). for lowest current consumption in this mode, place all i/o pins at either v dd or v ss , ensure no external cir- cuitry is drawing current from the i/o pin, power-down the a/d and disable external clocks. pull all i/o pins that are high-impedance inputs, high or low externally to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for low- est current consumption. the contribution from on-chip pull-ups on portb should be considered. the mclr pin must be at a logic high level (v ihmc ). 24.3.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from int pin, rb port change or a peripheral interrupt. the following peripheral interrupts can wake the device from sleep: 1. psp read or write. 2. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 3. tmr3 interrupt. timer3 must be operating as an asynchronous counter. 4. ccp capture mode interrupt. 5. special event trigger (timer1 in asynchronous mode using an external clock). 6. mssp (start/stop) bit detect interrupt. 7. mssp transmit or receive in slave mode (spi/i 2 c). 8. usart rx or tx (synchronous slave mode). 9. a/d conversion (when a/d clock source is rc). 10. eeprom write operation complete. 11. lvd interrupt. 12. can wake-up interrupt. other peripherals cannot generate interrupts since during sleep, no on-chip clocks are present. external mclr reset will cause a device reset. all other events are considered a continuation of program execution and will cause a ?wake-up?. the to and pd bits in the rcon register can be used to determine the cause of the device reset. the pd bit which is set on power-up is cleared when sleep is invoked. the to bit is cleared if a wdt time-out occurred (and caused wake-up). when the sleep instruction is being executed, the next instruction (pc + 2) is pre-fetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the inter- rupt address. in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. 24.3.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur:  if an interrupt condition (interrupt flag bit and interrupt enable bits are set) occurs before the execution of a sleep instruction, the sleep instruction will complete as a nop . therefore, the wdt and wdt postscaler will not be cleared, the to bit will not be set and pd bits will not be cleared.  if the interrupt condition occurs during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt postscaler will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction.
pic18f6585/8585/6680/8680 ds30491c-page 358 ? 2004 microchip technology inc. figure 24-2: wake-up from sleep through interrupt (1,2) q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clko (4) int pin intf flag (intcon<1>) gieh bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc+2 pc+4 inst(pc) = sleep inst(pc - 1) inst(pc + 2) sleep processor in sleep interrupt latency (3) inst(pc + 4) inst(pc + 2) inst(0008h) inst(000ah) inst(0008h) dummy cycle pc + 4 0008h 000ah dummy cycle t ost (2) pc+4 note 1: xt, hs or lp oscillator mode assumed. 2: gie = 1 assumed. in this case after wake-up, the processor jumps to the interrupt routine. if gie = 0 , execution will continue in-line. 3: t ost = 1024 t osc (drawing not to scale). this delay will not occur for rc and ec oscillator modes. 4: clko is not available in these oscillator modes but shown here for timing reference.
? 2004 microchip technology inc. ds30491c-page 359 pic18f6585/8585/6680/8680 24.4 program verification and code protection the overall structure of the code protection on the pic18 flash devices differs significantly from other picmicro ? devices. the user program memory is divided on binary bound- aries into four blocks of 16 kbytes each. the first block is further divided into a boot block of 2048 bytes and a second block (block 0) of 14 kbytes. each of the blocks has three code protection bits associated with them. they are:  code-protect bit (cpn)  write-protect bit (wrtn)  external block table read bit (ebtrn) figure 24-3 shows the program memory organization for 48 and 64-kbyte devices and the specific code protection bit associated with each block. the actual locations of the bits are summarized in table 24-3. figure 24-3: code-protected progra m memory for pic18fxx8x devices table 24-3: summary of code protection registers memory size/device block code protection controlled by: 48 kbytes (pic18fx585 64 kbytes (pic18fx680) address range boot block boot block 000000h 0007ffh cpb, wrtb, ebtrb block 0 block 0 000800h 003fffh cp0, wrt0, ebtr0 block 1 block 1 004000h 007fffh cp1, wrt1, ebtr1 block 2 block 2 008000h 00bfffh cp2, wrt2, ebtr2 unimplemented read ? 0 ? block 3 00c000h 00ffffh cp3, wrt3, ebtr3 file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 300008h config5l ? ? ? ?cp3 (1) cp2 cp1 cp0 300009h config5h cpd cpb ? ? ? ? ? ? 30000ah config6l ? ? ? ?wrt3 (1) wrt2 wrt1 wrt0 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 30000ch config7l ? ? ? ? ebtr3 (1) ebtr2 ebtr1 ebtr0 30000dh config7h ? ebtrb ? ? ? ? ? ? legend: shaded cells are unimplemented. note 1: unimplemented in pic18fx585 devices.
pic18f6585/8585/6680/8680 ds30491c-page 360 ? 2004 microchip technology inc. 24.4.1 program memory code protection the user memory may be read to or written from any location using the table read and table write instruc- tions. the device id may be read with table reads. the configuration registers may be read and written with the table read and table write instructions. in user mode, the cpn bits have no direct effect. cpn bits inhibit external reads and writes. a block of user memory may be protected from table writes if the wrtn configuration bit is ? 0 ?. the ebtrn bits control table reads. for a block of user memory with the ebtrn bit set to ? 0 ?, a table read instruction that exe- cutes from within that block is allowed to read. a table read instruction that executes from a location outside of that block is not allowed to read and will result in read- ing ? 0 ?s. figures 24-4 through 24-6 illustrate table write and table read protection. figure 24-4: table write (wrtn) disallowed note: code protection bits may only be written to a ? 0 ? from a ? 1 ? state. it is not possible to write a ? 1 ? to a bit in the ? 0 ? state. code protection bits are only set to ? 1 ? by a full chip erase or block erase function. the full chip erase and block erase functions can only be initiated via icsp or an external programmer. 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh wrtb, ebtrb = 11 wrt0, ebtr0 = 01 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblwt * tblptr = 000fffh pc = 003ffeh tblwt * pc = 008ffeh register values program memory configuration bit settings results: all table writes disabled to block n whenever wrtn = 0 .
? 2004 microchip technology inc. ds30491c-page 361 pic18f6585/8585/6680/8680 figure 24-5: external block t able read (ebtrn) disallowed figure 24-6: external block table read (ebtrn) allowed wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd * tblptr = 000fffh pc = 004ffeh results: all table reads from external blocks to block n are disabled whenever ebtrn = 0 . tablat register returns a value of ? 0 ?. register values program memory configuration bit settings 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh 000000h wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd * tblptr = 000fffh pc = 003ffeh register values program memory configuration bit settings results: table reads permitted within block n even when ebtrbn = 0 . tablat register returns the value of the data at the location tblptr. 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh 000000h
pic18f6585/8585/6680/8680 ds30491c-page 362 ? 2004 microchip technology inc. 24.4.2 data eeprom code protection the entire data eeprom is protected from external reads and writes by two bits: cpd and wrtd. cpd inhibits external reads and writes of data eeprom. wrtd inhibits external writes to data eeprom. the cpu can continue to read and write data eeprom regardless of the protection bit settings. 24.4.3 configuration register protection the configuration registers can be write-protected. the wrtc bit controls protection of the configuration regis- ters. in user mode, the wrtc bit is readable only. wrtc can only be written via icsp or an external programmer. 24.5 id locations eight memory locations (200000h-200007h) are designated as id locations where the user can store checksum or other code identification numbers. these locations are accessible during normal execution through the tblrd and tblwt instructions or during program/verify. the id locations can be read when the device is code-protected. 24.6 in-circuit serial programming pic18fxx80/xx85 microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data, and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 24.7 in-circuit debugger when the debug bit in configuration register, config4l, is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some of the resources are not available for general use. table 24-4 shows which features are consumed by the background debugger. table 24-4: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to mclr /v pp , v dd , gnd, rb7 and rb6. this will interface to the in-circuit debugger module available from microchip or one of the third party development tool companies. i/o pins rb6, rb7 stack 2 levels program memory 512 bytes data memory 10 bytes
? 2004 microchip technology inc. ds30491c-page 363 pic18f6585/8585/6680/8680 24.8 low-voltage icsp programming the lvp bit in configuration register, config4l, enables low-voltage icsp programming. this mode allows the microcontroller to be programmed via icsp using a v dd source in the operating voltage range. this only means that v pp does not have to be brought to v ihh but can instead be left at the normal operating voltage. in this mode, the rb5/kbi1/pgm pin is dedicated to the programming function and ceases to be a general pur- pose i/o pin. during programming, v dd is applied to the rg5/mclr /v pp pin. to enter programming mode, v dd must be applied to the rb5/kbi1/pgm pin, provided the lvp bit is set. the lvp bit defaults to a ? 1 ? from the factory. if low-voltage programming mode is not used, the lvp bit can be programmed to a ? 0 ? and rb5/kbi1/pgm becomes a digital i/o pin. however, the lvp bit may only be programmed when programming is entered with v ihh on rg5/mclr /v pp . it should be noted that once the lvp bit is programmed to ? 0 ?, only the high-voltage programming mode is available and only high-voltage programming mode can be used to program the device. when using low-voltage icsp, the part must be sup- plied 4.5v to 5.5v if a bulk erase will be executed. this includes reprogramming of the code-protect bits from an on-state to an off-state. for all other cases of low- voltage icsp, the part may be programmed at the normal operating voltage. this means unique user ids or user code can be reprogrammed or added. note 1: the high-voltage programming mode is always available regardless of the state of the lvp bit, by applying v ihh to the mclr pin. 2: while in low-voltage icsp mode, the rb5 pin can no longer be used as a general purpose i/o pin and should be held low during normal operation. 3: when using low-voltage icsp program- ming (lvp) and the pull-ups on portb are enabled, bit 5 in the trisb register must be cleared to disable the pull-up on rb5 and ensure the proper operation of the device. 4: if the device master clear is disabled, verify that either of the following is done to ensure proper entry into icsp mode: a) disable low-voltage programming (config4l<2> = 0 ); or b) make certain that rb5/kbi1/pgm is held low during entry into icsp.
pic18f6585/8585/6680/8680 ds30491c-page 364 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 365 pic18f6585/8585/6680/8680 25.0 instruction set summary the pic18 instruction set adds many enhancements to the previous picmicro instruction sets, while maintain- ing an easy migration from these picmicro instruction sets. most instructions are a single program memory word (16 bits) but there are three instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories:  byte-oriented operations  bit-oriented operations  literal operations  control operations the pic18 instruction set summary in table 25-2 lists byte-oriented , bit-oriented , literal and control operations. table 25-1 shows the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator ?f? specifies which file register is to be used by the instruction. the destination designator ?d? specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the wreg register. if ?d? is one, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator ?b? selects the number of the bit affected by the operation, while the file register desig- nator ?f? represents the number of the file in which the bit is located. the literal instructions may use some of the following operands:  a literal value to be loaded into a file register (specified by ?k?)  the desired fsr register to load the literal value into (specified by ?f?)  no operand required (specified by ???) the control instructions may use some of the following operands:  a program memory address (specified by ?n?)  the mode of the call or return instructions (specified by ?s?)  the mode of the table read and table write instructions (specified by ?m?)  no operand required (specified by ???) all instructions are a single word except for three double-word instructions. these three instructions were made double-word instructions so that all the required information is available in these 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle unless a conditional test is true or the program counter is changed as a result of the instruc- tion. in these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. two-word branch instructions (if true) would take 3 s. figure 25-1 shows the general formats that the instructions can have. all examples use the format ? nnh ? to represent a hexa- decimal number, where ? h ? signifies a hexadecimal digit. the instruction set summary, shown in table 25-2, lists the instructions recognized by the microchip assembler (mpasm tm ). section 25.1 ?instruction set? provides a description of each instruction.
pic18f6585/8585/6680/8680 ds30491c-page 366 ? 2004 microchip technology inc. table 25-1: opcode field descriptions field description a ram access bit a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7). bsr bank select register. used to select the current ram bank. d destination select bit d = 0 : store result in wreg d = 1 : store result in file register f dest destination either the wreg register or the specified register file location. f 8-bit register file address (0x00 to 0xff). fs 12-bit register file address (0x000 to 0xfff). this is the source address. fd 12-bit register file address (0x000 to 0xfff). this is the destination address. k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value). label label name. mm the mode of the tblptr register for the table read and table write instructions. only used with table read and table write instructions: * no change to register (such as tblptr with table reads and writes). *+ post-increment register (such as tblptr with table reads and writes). *- post-decrement register (such as tblptr with table reads and writes). +* pre-increment register (such as tblptr with table reads and writes). n the relative address (2?s complement number) for rela tive branch instructions, or the direct address for call/branch and return instructions. prodh product of multiply high byte. prodl product of multiply low byte. s fast call/return mode select bit s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) u unused or unchanged. wreg working register (accumulator). x don?t care (0 or 1). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. tblptr 21-bit table pointer (points to a program memory location). tablat 8-bit table latch. tos top-of-stack. pc program counter. pcl program counter low byte. pch program counter high byte. pclath program counter high byte latch. pclatu program counter upper byte latch. gie global interrupt enable bit. wdt watchdog timer. to time-out bit. pd power-down bit. c, dc, z, ov, n alu status bits: carry, digit carry, zero, overflow, negative. [ ] optional. ( ) contents. assigned to. < > register bit field. in the set of. italics user defined term (font is courier).
? 2004 microchip technology inc. ds30491c-page 367 pic18f6585/8585/6680/8680 figure 25-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call, goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 0x7f goto label 15 8 7 0 opcode n<7:0> (literal) 15 12 11 0 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc s
pic18f6585/8585/6680/8680 ds30491c-page 368 ? 2004 microchip technology inc. table 25-2: pic18fxxx instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented file register operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination) 2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1, 2 1, 2 1,2 2 1, 2 4 4 1, 2 1, 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 4 1, 2 1, 2 1 1, 2 1, 2 1, 2 1, 2 4 1, 2 bit-oriented file register operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, d, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1, 2 1, 2 3, 4 3, 4 1, 2 note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
? 2004 microchip technology inc. ds30491c-page 369 pic18f6585/8585/6680/8680 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine 1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 25-2: pic18fxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
pic18f6585/8585/6680/8680 ds30491c-page 370 ? 2004 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsrx 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 (5) 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none table 25-2: pic18fxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
? 2004 microchip technology inc. ds30491c-page 371 pic18f6585/8585/6680/8680 25.1 instruction set addlw add literal to w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example : addlw 0x15 before instruction w = 0x10 after instruction w = 0x25 addwf add w to f syntax: [ label ] addwf f [,d [,a] f [,d [,a] operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?d? (default). if ?a? is ? 0 ?, the access bank will be selected. if ?a? is ? 1 ?, the bsr is used. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : addwf reg, 0, 0 before instruction w = 0x17 reg = 0xc2 after instruction w=0xd9 reg = 0xc2
pic18f6585/8585/6680/8680 ds30491c-page 372 ? 2004 microchip technology inc. addwfc add w and carry bit to f syntax: [ label ] addwfc f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) + (c) dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory loca- tion ?f?. if ?a? is ? 0 ?, the access bank will be selected. if ?a? is ? 1 ?, the bsr will not be overridden. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : addwfc reg, 0, 1 before instruction carry bit = 1 reg = 0x02 w = 0x4d after instruction carry bit = 0 reg = 0x02 w = 0x50 andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. k w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example : andlw 0x5f before instruction w= 0xa3 after instruction w = 0x03
? 2004 microchip technology inc. ds30491c-page 373 pic18f6585/8585/6680/8680 andwf and w with f syntax: [ label ] andwf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (w) .and. (f) dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are and?ed with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected. if ?a? is ? 1 ?, the bsr will not be overridden (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : andwf reg, 0, 0 before instruction w = 0x17 reg = 0xc2 after instruction w = 0x02 reg = 0xc2 bc branch if carry syntax: [ label ] bc n operands: -128 n 127 operation: if carry bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bc 5 before instruction pc = address (here) after instruction if carry = 1; pc = address (here+12) if carry = 0; pc = address (here+2)
pic18f6585/8585/6680/8680 ds30491c-page 374 ? 2004 microchip technology inc. bcf bit clear f syntax: [ label ] bcf f,b[,a] operands: 0 f 255 0 b 7 a [0,1] operation: 0 f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : bcf flag_reg, 7, 0 before instruction flag_reg = 0xc7 after instruction flag_reg = 0x47 bn branch if negative syntax: [ label ] bn n operands: -128 n 127 operation: if negative bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bn jump before instruction pc = address (here) after instruction if negative = 1; pc = address (jump) if negative = 0; pc = address (here+2)
? 2004 microchip technology inc. ds30491c-page 375 pic18f6585/8585/6680/8680 bnc branch if not carry syntax: [ label ] bnc n operands: -128 n 127 operation: if carry bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bnc jump before instruction pc = address (here) after instruction if carry = 0; pc = address (jump) if carry = 1; pc = address (here+2) bnn branch if not negative syntax: [ label ] bnn n operands: -128 n 127 operation: if negative bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bnn jump before instruction pc = address (here) after instruction if negative = 0; pc = address (jump) if negative = 1; pc = address (here+2)
pic18f6585/8585/6680/8680 ds30491c-page 376 ? 2004 microchip technology inc. bnov branch if not overflow syntax: [ label ] bnov n operands: -128 n 127 operation: if overflow bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bnov jump before instruction pc = address (here) after instruction if overflow = 0; pc = address (jump) if overflow = 1; pc = address (here+2) bnz branch if not zero syntax: [ label ] bnz n operands: -128 n 127 operation: if zero bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bnz jump before instruction pc = address (here) after instruction if zero = 0; pc = address (jump) if zero = 1; pc = address (here+2)
? 2004 microchip technology inc. ds30491c-page 377 pic18f6585/8585/6680/8680 bra unconditional branch syntax: [ label ] bra n operands: -1024 n 1023 operation: (pc) + 2 + 2n pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example : here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: [ label ] bsf f,b[,a] operands: 0 f 255 0 b 7 a [0,1] operation: 1 f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, access bank will be selected, over- riding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : bsf flag_reg, 7, 1 before instruction flag_reg = 0x0a after instruction flag_reg = 0x8a
pic18f6585/8585/6680/8680 ds30491c-page 378 ? 2004 microchip technology inc. btfsc bit test file, skip if clear syntax: [ label ] btfsc f,b[,a] operands: 0 f 255 0 b 7 a [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (true) if flag<1> = 1; pc = address (false) btfss bit test file, skip if set syntax: [ label ] btfss f,b[,a] operands: 0 f 255 0 b < 7 a [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (false) if flag<1> = 1; pc = address (true)
? 2004 microchip technology inc. ds30491c-page 379 pic18f6585/8585/6680/8680 btg bit toggle f syntax: [ label ] btg f,b[,a] operands: 0 f 255 0 b < 7 a [0,1] operation: (f ) f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location ?f? is inverted. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : btg portc, 4, 0 before instruction: portc = 0111 0101 [0x75] after instruction: portc = 0110 0101 [0x65] bov branch if overflow syntax: [ label ] bov n operands: -128 n 127 operation: if overflow bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bov jump before instruction pc = address (here) after instruction if overflow = 1; pc = address (jump) if overflow = 0; pc = address (here+2)
pic18f6585/8585/6680/8680 ds30491c-page 380 ? 2004 microchip technology inc. bz branch if zero syntax: [ label ] bz n operands: -128 n 127 operation: if zero bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example : here bz jump before instruction pc = address (here) after instruction if zero = 1; pc = address (jump) if zero = 0; pc = address (here+2) call subroutine call syntax: [ label ] call k [,s] operands: 0 k 1048575 s [0,1] operation: (pc) + 4 tos, k pc<20:1>, if s = 1 (w) ws, (status) statuss, (bsr) bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc+ 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs (default). then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example : here call there,1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss = status
? 2004 microchip technology inc. ds30491c-page 381 pic18f6585/8585/6680/8680 clrf clear f syntax: [ label ] clrf f [,a] operands: 0 f 255 a [0,1] operation: 000h f 1 z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : clrf flag_reg,1 before instruction flag_reg = 0x5a after instruction flag_reg = 0x00 clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 000h wdt, 000h wdt postscaler, 1 to, 1 pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the postscaler of the wdt. status bits to and pd are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example : clrwdt before instruction wdt counter = ? after instruction wdt counter = 0x00 wdt postscaler = 0 to =1 pd =1
pic18f6585/8585/6680/8680 ds30491c-page 382 ? 2004 microchip technology inc. comf complement f syntax: [ label ] comf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are com- plemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : comf reg, 0, 0 before instruction reg = 0x13 after instruction reg = 0x13 w=0xec (f ) cpfseq compare f with w, skip if f = w syntax: [ label ] cpfseq f [,a] operands: 0 f 255 a [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg w; pc = address (nequal)
? 2004 microchip technology inc. ds30491c-page 383 pic18f6585/8585/6680/8680 cpfsgt compare f with w, skip if f > w syntax: [ label ] cpfsgt f [,a] operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data memory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg > w; pc = address (greater) if reg w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: [ label ] cpfslt f [,a] operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected. if ?a? is ? 1 ?, the bsr will not be overrid- den (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg w; pc = address (nless)
pic18f6585/8585/6680/8680 ds30491c-page 384 ? 2004 microchip technology inc. daw decimal adjust w register syntax: [ label ] daw operands: none operation: if [w<3:0> >9] or [dc = 1] then (w<3:0>) + 6 w<3:0>; else ( w<3:0>) w<3:0>; if [w<7:4> >9] or [c = 1] then ( w<7:4>) + 6 w<7:4>; else (w<7:4>) w<7:4>; status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the eight-bit value in w, resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example1 : daw before instruction w=0xa5 c=0 dc = 0 after instruction w = 0x05 c=1 dc = 0 example 2 : before instruction w=0xce c=0 dc = 0 after instruction w = 0x34 c=1 dc = 0 decf decrement f syntax: [ label ] decf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : decf cnt, 1, 0 before instruction cnt = 0x01 z=0 after instruction cnt = 0x00 z=1
? 2004 microchip technology inc. ds30491c-page 385 pic18f6585/8585/6680/8680 decfsz decrement f, skip if 0 syntax: [ label ] decfsz f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt - 1 if cnt = 0; pc = address (continue) if cnt 0; pc = address (here+2) dcfsnz decrement f, skip if not 0 syntax: [ label ] dcfsnz f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp - 1, if temp = 0; pc = address (zero) if temp 0; pc = address (nzero)
pic18f6585/8585/6680/8680 ds30491c-page 386 ? 2004 microchip technology inc. goto unconditional branch syntax: [ label ] goto k operands: 0 k 1048575 operation: k pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte memory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example : goto there after instruction pc = address (there) incf increment f syntax: [ label ] incf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : incf cnt, 1, 0 before instruction cnt = 0xff z=0 c=? dc = ? after instruction cnt = 0x00 z=1 c=1 dc = 1
? 2004 microchip technology inc. ds30491c-page 387 pic18f6585/8585/6680/8680 incfsz increment f, skip if 0 syntax: [ label ] incfsz f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruc- tion which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0; pc = address (zero) if cnt 0; pc = address (nzero) infsnz increment f, skip if not 0 syntax: [ label ] infsnz f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg 0; pc = address (nzero) if reg = 0; pc = address (zero)
pic18f6585/8585/6680/8680 ds30491c-page 388 ? 2004 microchip technology inc. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are or?ed with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example : iorlw 0x35 before instruction w = 0x9a after instruction w= 0xbf iorwf inclusive or w with f syntax: [ label ] iorwf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (w) .or. (f) dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : iorwf result, 0, 1 before instruction result = 0x13 w = 0x91 after instruction result = 0x13 w = 0x93
? 2004 microchip technology inc. ds30491c-page 389 pic18f6585/8585/6680/8680 lfsr load fsr syntax: [ label ] lfsr f,k operands: 0 f 2 0 k 4095 operation: k fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example : lfsr 2, 0x3ab after instruction fsr2h = 0x03 fsr2l = 0xab movf move f syntax: [ label ] movf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: f dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). location ?f? can be any- where in the 256-byte bank. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example : movf reg, 0, 0 before instruction reg = 0x22 w=0xff after instruction reg = 0x22 w = 0x22
pic18f6585/8585/6680/8680 ds30491c-page 390 ? 2004 microchip technology inc. movff move f to f syntax: [ label ] movff f s ,f d operands: 0 f s 4095 0 f d 4095 operation: (f s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff fff f s fff f d description: the contents of source register ?f s ? are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register words: 2 cycles: 2 (3) q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example : movff reg1, reg2 before instruction reg1 = 0x33 reg2 = 0x11 after instruction reg1 = 0x33, reg2 = 0x33 movlb move literal to low nibble in bsr syntax: [ label ] movlb k operands: 0 k 255 operation: k bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the 8-bit literal ?k? is loaded into the bank select register (bsr). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example : movlb 5 before instruction bsr register = 0x02 after instruction bsr register = 0x05
? 2004 microchip technology inc. ds30491c-page 391 pic18f6585/8585/6680/8680 movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example : movlw 0x5a after instruction w = 0x5a movwf move w to f syntax: [ label ] movwf f [,a] operands: 0 f 255 a [0,1] operation: (w) f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank will be selected, over- riding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : movwf reg, 0 before instruction w = 0x4f reg = 0xff after instruction w = 0x4f reg = 0x4f
pic18f6585/8585/6680/8680 ds30491c-page 392 ? 2004 microchip technology inc. mullw multiply literal with w syntax: [ label ] mullw k operands: 0 k 255 operation: (w) x k prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example : mullw 0xc4 before instruction w=0xe2 prodh = ? prodl = ? after instruction w=0xe2 prodh = 0xad prodl = 0x08 mulwf multiply w with f syntax: [ label ] mulwf f [,a] operands: 0 f 255 a [0,1] operation: (w) x (f) prodh:prodl status affected: none encoding: 0000 001a ffff ffff description:? an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example : mulwf reg, 1 before instruction w=0xc4 reg = 0xb5 prodh = ? prodl = ? after instruction w=0xc4 reg = 0xb5 prodh = 0x8a prodl = 0x94
? 2004 microchip technology inc. ds30491c-page 393 pic18f6585/8585/6680/8680 negf negate f syntax: [ label ] negf f [,a] operands: 0 f 255 a [0,1] operation: ( f ) + 1 f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : negf reg, 1 before instruction reg = 0011 1010 [0x3a] after instruction reg = 1100 0110 [0xc6] nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example : none.
pic18f6585/8585/6680/8680 ds30491c-page 394 ? 2004 microchip technology inc. pop pop top of return stack syntax: [ label ] pop operands: none operation: (tos) bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example : pop goto new before instruction tos = 0031a2h stack (1 level down)= 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: [ label ] push operands: none operation: (pc+2) tos status affected: none encoding: 0000 0000 0000 0101 description: the pc+2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implement- ing a software stack by modifying tos, and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc+2 onto return stack no operation no operation example : push before instruction tos = 00345ah pc = 000124h after instruction pc = 000126h tos = 000126h stack (1 level down)= 00345ah
? 2004 microchip technology inc. ds30491c-page 395 pic18f6585/8585/6680/8680 rcall relative call syntax: [ label ] rcall n operands: -1024 n 1023 operation: (pc) + 2 tos, (pc) + 2 + 2n pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc+2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc+2+2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example : here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here+2) reset reset syntax: [ label ] reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example : reset after instruction registers = reset value flags* = reset value
pic18f6585/8585/6680/8680 ds30491c-page 396 ? 2004 microchip technology inc. retfie return from interrupt syntax: [ label ] retfie [s] operands: s [0,1] operation: (tos) pc, 1 gie/gieh or peie/giel, if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged. status affected: gie/gieh, peie/giel. encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example : retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: [ label ] retlw k operands: 0 k 255 operation: k w, (tos) pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example : call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 0x07 after instruction w = value of kn
? 2004 microchip technology inc. ds30491c-page 397 pic18f6585/8585/6680/8680 return return from subroutine syntax: [ label ] return [s] operands: s [0,1] operation: (tos) pc, if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example : return after interrupt pc = tos rlcf rotate left f through carry syntax: [ label ] rlcf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) c, (c) dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? = 1 , then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : rlcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 1100 1100 c=1 c register f
pic18f6585/8585/6680/8680 ds30491c-page 398 ? 2004 microchip technology inc. rlncf rotate left f (no carry) syntax: [ label ] rlncf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ,? the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: [ label ] rrcf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) c, (c) dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : rrcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 0111 0011 c=0 c register f
? 2004 microchip technology inc. ds30491c-page 399 pic18f6585/8585/6680/8680 rrncf rotate right f (no carry) syntax: [ label ] rrncf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) dest<7> status affected: n, z encoding: 0100 00da ffff ffff description:? the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1 : rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2 : rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w= 1110 1011 reg = 1101 0111 register f setf set f syntax: [ label ] setf f [,a] operands: 0 f 255 a [0,1] operation: ffh f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example : setf reg,1 before instruction reg = 0x5a after instruction reg = 0xff
pic18f6585/8585/6680/8680 ds30491c-page 400 ? 2004 microchip technology inc. sleep enter sleep mode syntax: [ label ] sleep operands: none operation: 00h wdt, 0 wdt postscaler, 1 to , 0 pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example : sleep before instruction to =? pd =? after instruction to =1 ? pd =0 ? if wdt causes wake-up, this bit is cleared. subfwp subtract f from w with borrow syntax: [ label ] subfwb f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (w) ? (f) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1 : subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2 : subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3 : subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
? 2004 microchip technology inc. ds30491c-page 401 pic18f6585/8585/6680/8680 sublw subtract w from literal syntax: [ label ]sublw k operands: 0 k 255 operation: k ? (w) w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description: w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 0x02 before instruction w= 1 c= ? after instruction w= 1 c = 1 ; result is positive z=0 n= 0 example 2 : sublw 0x02 before instruction w= 2 c= ? after instruction w= 0 c = 1 ; result is zero z=1 n= 0 example 3 : sublw 0x02 before instruction w= 3 c= ? after instruction w = ff ; (2?s complement) c = 0 ; result is negative z=0 n= 1 subwf subtract w from f syntax: [ label ] subwf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1 : subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2 : subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c=1; result is zero z=1 n=0 example 3 : subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f6585/8585/6680/8680 ds30491c-page 402 ? 2004 microchip technology inc. subwfb subtract w from f with borrow syntax: [ label ] subwfb f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (bor- row) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1 : subwfb reg, 1, 0 before instruction reg = 0x19 (0001 1001) w = 0x0d (0000 1101) c=1 after instruction reg = 0x0c (0000 1011) w = 0x0d (0000 1101) c=1 z=0 n = 0 ; result is positive example 2 : subwfb reg, 0, 0 before instruction reg = 0x1b (0001 1011) w = 0x1a (0001 1010) c=0 after instruction reg = 0x1b (0001 1011) w = 0x00 c=1 z = 1 ; result is zero n=0 example 3: subwfb reg, 1, 0 before instruction reg = 0x03 (0000 0011) w = 0x0e (0000 1101) c=1 after instruction reg = 0xf5 (1111 0100) ; [2?s comp] w = 0x0e (0000 1101) c=0 z=0 n = 1 ; result is negative swapf swap f syntax: [ label ] swapf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (f<3:0>) dest<7:4>, (f<7:4>) dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : swapf reg, 1, 0 before instruction reg = 0x53 after instruction reg = 0x35
? 2004 microchip technology inc. ds30491c-page 403 pic18f6585/8585/6680/8680 tblrd table read syntax: [ label ] tblrd ( *; *+; *-; +*) operands: none operation: if tblrd *, (prog mem (tblptr)) tablat; tblptr ? no change; if tblrd *+, (prog mem (tblptr)) tablat; (tblptr) + 1 tblptr; if tblrd *-, (prog mem (tblptr)) tablat; (tblptr) ? 1 tblptr; if tblrd +*, (tblptr) + 1 tblptr; (prog mem (tblptr)) tablat; status affected:none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer called table pointer (tblptr) is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows:  no change  post-increment  post-decrement  pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example1 : tblrd *+ ; before instruction tablat = 0x55 tblptr = 0x00a356 memory(0x00a356) = 0x34 after instruction tablat = 0x34 tblptr = 0x00a357 example2 : tblrd +* ; before instruction tablat = 0xaa tblptr = 0x01a357 memory(0x01a357) = 0x12 memory(0x01a358) = 0x34 after instruction tablat = 0x34 tblptr = 0x01a358
pic18f6585/8585/6680/8680 ds30491c-page 404 ? 2004 microchip technology inc. tblwt table write syntax: [ label ] tblwt ( *; *+; *-; +*) operands: none operation: if tblwt*, (tablat) holding register; tblptr ? no change; if tblwt*+, (tablat) holding register; (tblptr) + 1 tblptr; if tblwt*-, (tablat) holding register; (tblptr) ? 1 tblptr; if tblwt+*, (tblptr) + 1 tblptr; (tablat) holding register; status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 5.0 ?flash program memory? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbtye address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 :most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows:  no change  post-increment  post-decrement  pre-increment tblwt table write (continued) words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register ) example1 : tblwt *+; before instruction tablat = 0x55 tblptr = 0x00a356 holding register (0x00a356) = 0xff after instructions (table write completion) tablat = 0x55 tblptr = 0x00a357 holding register (0x00a356) = 0x55 example 2 : tblwt +*; before instruction tablat = 0x34 tblptr = 0x01389a holding register (0x01389a) = 0xff holding register (0x01389b) = 0xff after instruction (table write completion) tablat = 0x34 tblptr = 0x01389b holding register (0x01389a) = 0xff holding register (0x01389b) = 0x34
? 2004 microchip technology inc. ds30491c-page 405 pic18f6585/8585/6680/8680 tstfsz test f, skip if 0 syntax: [ label ] tstfsz f [,a] operands: 0 f 255 a [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction, fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example : here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 0x00, pc = address (zero) if cnt 0x00, pc = address (nzero) xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 k 255 operation: (w) .xor. k w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example : xorlw 0xaf before instruction w= 0xb5 after instruction w = 0x1a
pic18f6585/8585/6680/8680 ds30491c-page 406 ? 2004 microchip technology inc. xorwf exclusive or w with f syntax: [ label ] xorwf f [,d [,a]] operands: 0 f 255 d [0,1] a [0,1] operation: (w) .xor. (f) dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example : xorwf reg, 1, 0 before instruction reg = 0xaf w=0xb5 after instruction reg = 0x1a w=0xb5
? 2004 microchip technology inc. ds30491c-page 407 pic18f6585/8585/6680/8680 26.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools:  integrated development environment - mplab ? ide software  assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian - mplab c30 c compiler - mplab asm30 assembler/linker/library  simulators - mplab sim software simulator - mplab dspic30 software simulator emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator  in-circuit debugger - mplab icd 2  device programmers -pro mate ? ii universal device programmer - picstart ? plus development programmer - mplab pm3 device programmer  low-cost demonstration boards - picdem tm 1 demonstration board - picdem.net tm demonstration board - picdem 2 plus demonstration board - picdem 3 demonstration board - picdem 4 demonstration board - picdem 17 demonstration board - picdem 18r demonstration board - picdem lin demonstration board - picdem usb demonstration board  evaluation kits -k ee l oq ? - picdem msc -microid ? -can - powersmart ? -analog 26.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? based application that contains:  an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately)  a full-featured editor with color coded context  a multiple project manager  customizable data windows with direct edit of contents  high-level source code debugging  mouse over variable inspection  extensive on-line help the mplab ide allows you to:  edit your source files (either assembly or c)  one touch assemble (or compile) and download to picmicro emulator and simulator tools (automatically updates all project information)  debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increasing flexibility and power. 26.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol ref- erence, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include:  integration into mplab ide projects  user defined macros to streamline assembly code  conditional assembly for multi-purpose source files  directives that allow complete control over the assembly process
pic18f6585/8585/6680/8680 ds30491c-page 408 ? 2004 microchip technology inc. 26.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi c compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 26.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include:  efficient linking of single libraries instead of many smaller files  enhanced code maintainability by grouping related modules together  flexible creation of libraries with easy module listing, replacement, deletion and extraction 26.5 mplab c30 c compiler the mplab c30 c compiler is a full-featured, ansi compliant, optimizing compiler that translates standard ansi c programs into dspic30f assembly language source. the compiler also supports many command line options and language extensions to take full advantage of the dspic30f device hardware capabili- ties and afford fine control of the compiler code generator. mplab c30 is distributed with a complete ansi c standard library. all library functions have been vali- dated and conform to the ansi c library standard. the library includes functions for string manipulation, dynamic memory allocation, data conversion, time- keeping and math functions (trigonometric, exponential and hyperbolic). the compiler provides symbolic information for high-level source debugging with the mplab ide. 26.6 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 compiler uses the assembler to produce it?s object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include:  support for the entire dspic30f instruction set  support for fixed-point and floating-point data  command line interface  rich directive set  flexible macro language  mplab ide compatibility 26.7 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any pin. the execu- tion can be performed in single-step, execute until break or trace mode. the mplab sim simulator fully supports symbolic debugging using the mplab c17 and mplab c18 c compilers, as well as the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool. 26.8 mplab sim30 software simulator the mplab sim30 software simulator allows code development in a pc hosted environment by simulating the dspic30f series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any of the pins. the mplab sim30 simulator fully supports symbolic debugging using the mplab c30 c compiler and mplab asm30 assembler. the simulator runs in either a command line mode for automated tasks, or from mplab ide. this high-speed simulator is designed to debug, analyze and optimize time intensive dsp routines.
? 2004 microchip technology inc. ds30491c-page 409 pic18f6585/8585/6680/8680 26.9 mplab ice 2000 high-performance universal in-circuit emulator the mplab ice 2000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 26.10 mplab ice 4000 high-performance universal in-circuit emulator the mplab ice 4000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high- end picmicro microcontrollers. software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab icd 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high-speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, up to 2 mb of emulation memory and the ability to view variables in real-time. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 26.11 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro microcontrollers. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single-stepping and watching variables, cpu status and peripheral registers. running at full speed enables testing hardware and applications in real-time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 26.12 pro mate ii universal device programmer the pro mate ii is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features an lcd display for instructions and error messages and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. 26.13 mplab pm3 device programmer the mplab pm3 is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modular detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand- alone mode, the mplab pm3 device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. mplab pm3 connects to the host pc via an rs-232 or usb cable. mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorpo- rates an sd/mmc card for file storage and secure data applications.
pic18f6585/8585/6680/8680 ds30491c-page 410 ? 2004 microchip technology inc. 26.14 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 26.15 picdem 1 picmicro demonstration board the picdem 1 demonstration board demonstrates the capabilities of the pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the sample microcontrollers provided with the picdem 1 demonstration board can be programmed with a pro mate ii device program- mer or a picstart plus development programmer. the picdem 1 demonstration board can be connected to the mplab ice in-circuit emulator for testing. a prototype area extends the circuitry for additional appli- cation components. features include an rs-232 interface, a potentiometer for simulated analog input, push button switches and eight leds. 26.16 picdem.net internet/ethernet demonstration board the picdem.net demonstration board is an internet/ ethernet demonstration board using the pic18f452 microcontroller and tcp/ip firmware. the board supports any 40-pin dip device that conforms to the standard pinout used by the pic16f877 or pic18c452. this kit features a user friendly tcp/ip stack, web server with html, a 24l256 serial eeprom for xmodem download to web pages into serial eeprom, icsp/mplab icd 2 interface con- nector, an ethernet interface, rs-232 interface and a 16 x 2 lcd display. also included is the book and cd-rom ?tcp/ip lean, web servers for embedded systems,? by jeremy bentham 26.17 picdem 2 plus demonstration board the picdem 2 plus demonstration board supports many 18, 28 and 40-pin microcontrollers, including pic16f87x and pic18fxx2 devices. all the neces- sary hardware and software is included to run the dem- onstration programs. the sample microcontrollers provided with the picdem 2 demonstration board can be programmed with a pro mate ii device program- mer, picstart plus development programmer, or mplab icd 2 with a universal programmer adapter. the mplab icd 2 and mplab ice in-circuit emulators may also be used with the picdem 2 demonstration board to test firmware. a prototype area extends the circuitry for additional application components. some of the features include an rs-232 interface, a 2 x 16 lcd display, a piezo speaker, an on-board temperature sensor, four leds and sample pic18f452 and pic16f877 flash microcontrollers. 26.18 picdem 3 pic16c92x demonstration board the picdem 3 demonstration board supports the pic16c923 and pic16c924 in the plcc package. all the necessary hardware and software is included to run the demonstration programs. 26.19 picdem 4 8/14/18-pin demonstration board the picdem 4 can be used to demonstrate the capa- bilities of the 8, 14 and 18-pin pic16xxxx and pic18xxxx mcus, including the pic16f818/819, pic16f87/88, pic16f62xa and the pic18f1320 family of microcontrollers. picdem 4 is intended to showcase the many features of these low pin count parts, including lin and motor control using eccp. special provisions are made for low-power operation with the supercapacitor circuit and jumpers allow on- board hardware to be disabled to eliminate current draw in this mode. included on the demo board are pro- visions for crystal, rc or canned oscillator modes, a five volt regulator for use with a nine volt wall adapter or battery, db-9 rs-232 interface, icd connector for programming via icsp and development with mplab icd 2, 2 x 16 liquid crystal display, pcb footprints for h-bridge motor driver, lin transceiver and eeprom. also included are: header for expansion, eight leds, four potentiometers, three push buttons and a proto- typing area. included with the kit is a pic16f627a and a pic18f1320. tutorial firmware is included along with the user?s guide.
? 2004 microchip technology inc. ds30491c-page 411 pic18f6585/8585/6680/8680 26.20 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. a pro- grammed sample is included. the pro mate ii device programmer, or the picstart plus development pro- grammer, can be used to reprogram the device for user tailored application development. the picdem 17 demonstration board supports program download and execution from external on-board flash memory. a generous prototype area is available for user hardware expansion. 26.21 picdem 18r pic18c601/801 demonstration board the picdem 18r demonstration board serves to assist development of the pic18c601/801 family of microchip microcontrollers. it provides hardware implementation of both 8-bit multiplexed/demultiplexed and 16-bit memory modes. the board includes 2 mb external flash memory and 128 kb sram memory, as well as serial eeprom, allowing access to the wide range of memory types supported by the pic18c601/801. 26.22 picdem lin pic16c43x demonstration board the powerful lin hardware and software kit includes a series of boards and three picmicro microcontrollers. the small footprint pic16c432 and pic16c433 are used as slaves in the lin communication and feature on-board lin transceivers. a pic16f874 flash microcontroller serves as the master. all three micro- controllers are programmed with firmware to provide lin bus communication. 26.23 pickit tm 1 flash starter kit a complete ?development system in a box?, the pickit flash starter kit includes a convenient multi-section board for programming, evaluation and development of 8/14-pin flash pic ? microcontrollers. powered via usb, the board operates under a simple windows gui. the pickit 1 starter kit includes the user?s guide (on cd rom), pickit 1 tutorial software and code for various applications. also included are mplab ? ide (integrated development environment) software, software and hardware ?tips 'n tricks for 8-pin flash pic ? microcontrollers? handbook and a usb interface cable. supports all current 8/14-pin flash pic microcontrollers, as well as many future planned devices. 26.24 picdem usb pic16c7x5 demonstration board the picdem usb demonstration board shows off the capabilities of the pic16c745 and pic16c765 usb microcontrollers. this board provides the basis for future usb products. 26.25 evaluation and programming tools in addition to the picdem series of circuits, microchip has a line of evaluation kits and demonstration software for these products. k ee l oq evaluation and programming tools for microchip?s hcs secure data products  can developers kit for automotive network applications  analog design boards and filter design software  powersmart battery charging evaluation/ calibration kits irda ? development kit  microid development and rflab tm development software  seeval ? designer kit for memory evaluation and endurance calculations  picdem msc demo boards for switching mode power supply, high-power ir driver, delta sigma adc and flow rate sensor check the microchip web page and the latest product selector guide for the complete list of demonstration and evaluation kits.
pic18f6585/8585/6680/8680 ds30491c-page 412 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 413 pic18f6585/8585/6680/8680 27.0 electrical characteristics absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-55c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd , mclr , and ra4) ......................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +5.5v voltage on mclr with respect to v ss (note 2) ......................................................................................... 0v to +13.25v voltage on ra4 with respect to vss ............................................................................................. .................. 0v to +8.5v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ...................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports ...................................................................................................................... .200 ma maximum current sourced by all ports ........................................................................................... .......................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v o l x i ol ) 2: voltage spikes below v ss at the mclr /v pp pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 ? should be used when applying a ?low? level to the mclr /v pp pin rather than pulling this pin directly to v ss . ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f6585/8585/6680/8680 ds30491c-page 414 ? 2004 microchip technology inc. figure 27-1: pic18f6585/8585/6680/8680 voltage-frequency graph (industrial) figure 27-2: pic18lf6585/8585/6680/8680 voltage-frequency graph (industrial) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v f max 5.0v 3.5v 3.0v 2.5v pic18fxx8x 4.2v f max = 40 mhz for pic18f6x8x and pic18f8x8x in microcontroller mode. f max = 25 mhz for pic18f8x8x in modes other than microcontroller mode. frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v f max 5.0v 3.5v 3.0v 2.5v pic18lfxx8x f max = (16.36 mhz/v) (v ddappmin ? 2.0v) + 4 mhz, if v ddappmin 4.2v; note: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 4.2v f max = 40 mhz, if v ddappmin > 4.2v. for pic18f6x8x and pic18f8x8x in microcontroller mode: f max = (9.55 mhz/v) (v ddappmin ? 2.0v) + 4 mhz, if v ddappmin 4.2v; f max = 25 mhz, if v ddappmin > 4.2v. for pic18f8x8x in modes other than microcontroller mode:
? 2004 microchip technology inc. ds30491c-page 415 pic18f6585/8585/6680/8680 figure 27-3: pic18f6585/8585/6680/8680 voltage-frequency graph (extended) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 25 mhz 5.0v 3.5v 3.0v 2.5v pic18fxx8x 4.2v
pic18f6585/8585/6680/8680 ds30491c-page 416 ? 2004 microchip technology inc. 27.1 dc characteristics: supply voltage pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) pic18lfxx8x (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18fxx8x (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param. no. symbol characteristic min typ max units conditions d001 v dd supply voltage pic18lfxx8x 2.0 ? 5.5 v hs, xt, rc and lp oscillator mode pic18fxx8x 4.2 ? 5.5 v d001a av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ? ? 0.7 v see section on power-on reset for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details d005 v bor brown-out reset voltage borv1:borv0 = 11 1.96 ? 2.18 v borv1:borv0 = 10 2.64 ? 2.92 v borv1:borv0 = 01 4.11 ? 4.55 v borv1:borv0 = 00 4.41 ? 4.87 v legend: shading of rows is to assist in readability of the table. note 1: this is the limit to which v dd can be lowered in sleep mode, or during a device reset, without losing ram data.
? 2004 microchip technology inc. ds30491c-page 417 pic18f6585/8585/6680/8680 27.2 dc characteristics: power-down and supply current pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) pic18lfxx8x (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18fxx8x (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param. no. device typ max units conditions power-down current (i pd ) (1) d020 pic18lfxx8x 0.2 1 a -40c v dd = 2.0v, (sleep mode) 0.2 1 a+25c 5.0 10 a+85c d020a pic18lfxx8x 0.4 1 a -40c v dd = 3.0v, (sleep mode) 0.4 1 a+25c 3.0 18 a+85c d020b all devices 0.7 2 a -40c v dd = 5.0v, (sleep mode) 0.7 2 a+25c 15.0 32 a+85c legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic18f6585/8585/6680/8680 ds30491c-page 418 ? 2004 microchip technology inc. supply current (i dd ) (2,3) d010 pic18lfxx8x 500 500 a-40c f osc = 1 mh z , ec oscillator 300 500 a +25c v dd = 2.0v 850 1000 a+85c pic18lfxx8x 500 900 a-40c 500 900 a +25c v dd = 3.0v 11.5ma +85c all devices 1 2 ma -40c 12ma +25c v dd = 5.0v 1.3 3 ma +85c pic18lfxx8x 1 2 ma -40c f osc = 4 mhz, ec oscillator 12ma +25c v dd = 2.0v 1.5 2.5 ma +85c pic18lfxx8x 1.5 2 ma -40c 1.5 2 ma +25c v dd = 3.0v 22.5ma +85c all devices 3 5 ma -40c 35ma +25c v dd = 5.0v 46ma +85c 27.2 dc characteristics: power-down and supply current pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) (continued) pic18lfxx8x (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18fxx8x (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param. no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2004 microchip technology inc. ds30491c-page 419 pic18f6585/8585/6680/8680 supply current (i dd ) (2,3) pic18fxx8x 13 27 ma -40c f osc = 25 mh z , ec oscillator 15 27 ma +25c v dd = 4.2v 19 29 ma +85c pic18fxx8x 17 31 ma -40c 21 31 ma +25c v dd = 5.0v 23 34 ma +85c pic18fxx8x 20 34 ma -40c f osc = 40 mh z , ec oscillator 24 34 ma +25c v dd = 4.2v 29 44 ma +85c pic18fxx8x 28 46 ma -40c 33 46 ma +25c v dd = 5.0v 40 51 ma +85c d014 pic18lfxx8x 27 45 a-10c f osc = 32 khz, timer1 as clock 30 50 a +25c v dd = 2.0v 32 54 a+70c pic18lfxx8x 33 55 a-10c 36 60 a +25c v dd = 3.0v 39 65 a+70c all devices 75 125 a-10c 90 150 a +25c v dd = 5.0v 113 188 a+70c 27.2 dc characteristics: power-down and supply current pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) (continued) pic18lfxx8x (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18fxx8x (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param. no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic18f6585/8585/6680/8680 ds30491c-page 420 ? 2004 microchip technology inc. module differential currents ( ? i wdt , ? i bor , ? i lvd , ? i oscb , ? i ad ) d022 ( ? i wdt ) watchdog timer <1 1.5 a-40 c v dd = 2.0v <1 2 a+25 c 520 a+85 c 310 a-40 c v dd = 3.0v 320 a+25 c 10 35 a+85 c 12 25 a-40 c v dd = 5.0v 15 35 a+25 c 20 50 a+85 c d022a ( ? i bor ) brown-out reset 55 115 a-40 c to +85 cv dd = 3.0v 105 175 a-40 c to +85 cv dd = 5.0v d022b ( ? i lvd ) low-voltage detect 45 125 a-40 c to +85 cv dd = 2.0v 45 150 a-40 c to +85 cv dd = 3.0v 45 225 a-40 c to +85 cv dd = 5.0v d025 ( ? i oscb ) timer1 oscillator 20 27 a-10 c 20 30 a+25 cv dd = 2.0v 32 khz on timer1 25 35 a+70 c 22 60 a-10 c 22 65 a+25 cv dd = 3.0v 32 khz on timer1 25 75 a+70 c 30 75 a-10 c 30 85 a+25 cv dd = 5.0v 32 khz on timer1 35 100 a+70 c d026 ( ? i ad ) a/d converter <1 2 a+25 cv dd = 2.0v <1 2 a+25 cv dd = 3.0v a/d on, not converting <1 2 a+25 cv dd = 5.0v 27.2 dc characteristics: power-down and supply current pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) (continued) pic18lfxx8x (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18fxx8x (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param. no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2004 microchip technology inc. ds30491c-page 421 pic18f6585/8585/6680/8680 27.3 dc characteristics: pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. symbol characteristic min max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss 0.15 v dd vv dd < 4.5v d030a ? 0.8 v 4.5v v dd 5.5v d031 with schmitt trigger buffer rc3 and rc4 v ss v ss 0.2 v dd 0.3 v dd v v d032 mclr v ss 0.2 v dd v d032a osc1 (in xt, hs and lp modes) and t1osi v ss 0.3 v dd v d033 osc1 (in rc and ec mode) (1) v ss 0.2 v dd v v ih input high voltage i/o ports: d040 with ttl buffer 0.25 v dd + 0.8v v dd vv dd < 4.5v d040a 2.0 v dd v4.5v v dd 5.5v d041 with schmitt trigger buffer rc3 and rc4 0.8 v dd 0.7 v dd v dd v dd v v d042 mclr , osc1 (ec mode) 0.8 v dd v dd v d042a osc1 (in xt, hs and lp modes) and t1osi 0.7 v dd v dd v d043 osc1 (rc mode) (1) 0.9 v dd v dd v i il input leakage current (2,3) d060 i/o ports ? 1 av ss v pin v dd , pin at high-impedance d061 mclr ? 5 avss v pin v dd d063 osc1 ? 5 avss v pin v dd i pu weak pull-up current d070 i purb portb weak pull-up current 50 400 av dd = 5v, v pin = v ss note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
pic18f6585/8585/6680/8680 ds30491c-page 422 ? 2004 microchip technology inc. v ol output low voltage d080 i/o ports ? 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +85 c d080a ? 0.6 v i ol = 7.0 ma, v dd = 4.5v, -40 c to +125 c d083 osc2/clko (rc mode) ?0.6vi ol = 1.6 ma, v dd = 4.5v, -40 c to +85 c d083a ? 0.6 v i ol = 1.2 ma, v dd = 4.5v, -40 c to +125 c v oh output high voltage (3) d090 i/o ports v dd ? 0.7 ? v i oh = -3.0 ma, v dd = 4.5v, -40 c to +85 c d090a v dd ? 0.7 ? v i oh = -2.5 ma, v dd = 4.5v, -40 c to +125 c d092 osc2/clko (rc mode) v dd ? 0.7 ? v i oh = -1.3 ma, v dd = 4.5v, -40 c to +85 c d092a v dd ? 0.7 ? v i oh = -1.0 ma, v dd = 4.5v, -40 c to +125 c d150 v od open-drain high voltage ? 8.5 v ra4 pin capacitive loading specs on output pins d100 (4) c osc2 osc2 pin ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 c io all i/o pins and osc2 (in rc mode) ? 50 pf to meet the ac timing specifications d102 c b scl, sda ? 400 pf in i 2 c mode 27.3 dc characteristics: pic18fxx8x (industrial, extended) pic18lfxx8x (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. symbol characteristic min max units conditions note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
? 2004 microchip technology inc. ds30491c-page 423 pic18f6585/8585/6680/8680 table 27-1: comparator specifications table 27-2: voltage reference specifications operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +125c, unless otherwise stated param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 10 mv d301 v icm input common mode voltage 0 ? v dd ? 1.5 v d302 cmrr common mode rejection ratio 55 ? ? db 300 300a t resp response time (1) ?150400 600 ns ns pic18fxx8x pic18lfxx8x 301 t mc 2 ov comparator mode change to output valid ?? 10 s note 1: response time measured with one comparator input at (v dd ? 1.5)/2 while the other input transitions from v ss to v dd . operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +125c, unless otherwise stated param no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 v raa absolute accuracy ? ? ? ? 1/4 1/2 lsb lsb low range (vrr = 1 ) high range (vrr = 0 ) d312 v rur unit resistor value (r) ? 2k ? ? 310 t set settling time (1) ? ? 10 s note 1: settling time measured while vrr = 1 and vr<3:0> transitions from 0000 to 1111 .
pic18f6585/8585/6680/8680 ds30491c-page 424 ? 2004 microchip technology inc. figure 27-4: low-voltage detect characteristics table 27-3: low-voltage detect characteristics v lvd lvdif v dd (lvdif set by hardware) (lvdif can be cleared in software) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. symbol characteristic min typ? max units conditions d420 lvd voltage on v dd transition high to low lvv = 0000 ??? v lvv = 0001 1.96 2.06 2.16 v lvv = 0010 2.16 2.27 2.38 v lvv = 0011 2.35 2.47 2.59 v lvv = 0100 2.46 2.58 2.71 v lvv = 0101 2.64 2.78 2.92 v lvv = 0110 2.75 2.89 3.03 v lvv = 0111 2.95 3.1 3.26 v lvv = 1000 3.24 3.41 3.58 v lvv = 1001 3.43 3.61 3.79 v lvv = 1010 3.53 3.72 3.91 v lvv = 1011 3.72 3.92 4.12 v lvv = 1100 3.92 4.13 4.33 v lvv = 1101 4.11 4.33 4.55 v lvv = 1110 4.41 4.64 4.87 v d423 v bg band gap reference voltage value ?1.22? v ? production tested at t amb = 25c. specifications over temperat ure limits ensured by characterization.
? 2004 microchip technology inc. ds30491c-page 425 pic18f6585/8585/6680/8680 table 27-4: memory programming requirements dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions internal program memory programming specifications (note 1) d110 v pp voltage on mclr /v pp pin 9.00 ? 13.25 v (note 2) d112 i pp current into mclr /v pp pin ? ? 5 a d113 i ddp supply current during programming ??10ma data eeprom memory d120 e d cell endurance 100k 1m ? e/w -40 c to +85 c d120a e d cell endurance 10k 100k ? e/w +85 c to +125 c d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write, v min = minimum operating voltage d122 t dew erase/write cycle time ? 4 ? ms d123 t retd characteristic retention 40 ? ? year -40 c to +85 c (note 3) d123a t retd characteristic retention 100 ? ? year 25 c (note 3) program flash memory d130 e p cell endurance 10k 100k ? e/w -40 c to +85 c d130a e p cell endurance 1000 10k ? e/w +85 c to +125 c d131 v pr v dd for read v min ?5.5vv min = minimum operating voltage d132 v ie v dd for block erase 4.5 ? 5.5 v using icsp port d132a v iw v dd for externally timed erase or write 4.5 ? 5.5 v using icsp port d132b v pew v dd for self-timed write v min ?5.5vv min = minimum operating voltage d133 t ie icsp block erase cycle time ? 5 ? ms v dd > 4.5v d133a t iw icsp erase or write cycle time (externally timed) 1??msv dd > 4.5v d133a t iw self-timed write cycle time ? 2.5 ? ms d134 t retd characteristic retention 40 ? ? year -40 c to +85 c (note 3) d134a t retd characteristic retention 100 ? ? year 25 c (note 3) ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: these specifications are for programming the on-chip program memory through the use of table write instructions. 2: the pin may be kept in this range at times other than programming but it is not recommended. 3: retention time is valid provided no other specifications are violated.
pic18f6585/8585/6680/8680 ds30491c-page 426 ? 2004 microchip technology inc. 27.4 ac (timing) characteristics 27.4.1 timing parameter symbology the timing parameter symbols have been created following one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
? 2004 microchip technology inc. ds30491c-page 427 pic18f6585/8585/6680/8680 27.4.2 timing conditions the temperature and voltages specified in table 27-5 apply to all timing specifications unless otherwise noted. figure 27-5 specifies the load conditions for the timing specifications. table 27-5: temperature and voltage specifications - ac figure 27-5: load conditions for devi ce timing specifications ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended operating voltage v dd range as described in dc spec section 27.1 and section 27.3 . lc parts operate for industrial temperatures only. v dd /2 c l r l pin pin v ss v ss c l r l =464 ? c l = 50 pf for all pins except osc2/clko and including d and e outputs as ports load condition 1 load condition 2
pic18f6585/8585/6680/8680 ds30491c-page 428 ? 2004 microchip technology inc. 27.4.3 timing diagrams and specifications figure 27-6: external clock timing (all modes except pll) table 27-6: external clock timing requirements param. no. symbol characteristic min max units conditions 1a f osc external clki frequency (1) dc 40 mhz ec, ecio, -40c to +85c dc 25 mhz ec,ecio, -40c to +85c, ema oscillator frequency (1) dc 25 mhz ec, ecio, +85c to +125c dc 16 mhz ec, ecio, +85c to +125c, ema dc 4 mhz rc oscillator 0.1 4 mhz xt oscillator 4 25 mhz hs oscillator, -40c to +85c 4 25 mhz hs oscillator, -40c to +85c, ema 4 25 mhz hs oscillator, +85c to +125c 4 16 mhz hs oscillator, +85c to +125c, ema 4 10 mhz hs + pll oscillator, -40c to +85c 4 6.25 mhz hs + pll oscillator, +85c to +125c dc 200 khz lp oscillator 1t osc external clki period (1) 25 ? ns ec, ecio, -40c to +85c oscillator period (1) 40 ? ns ec,ecio, -40c to +85c, ema 40 ? ns ec, ecio, +85c to +125c 62.5 ? ns ec, ecio, +85c to +125c, ema 250 ? ns rc oscillator 250 10,000 ns xt oscillator 40 ? ns hs oscillator, -40c to +85c 40 ? ns hs oscillator, -40c to +85c, ema 40 ? ns hs oscillator, +85c to +125c 62.5 ? ns hs oscillator, +85c to +125c, ema 100 250 ns hs + pll oscillator, -40c to +85c 160 250 ns hs + pll oscillator, +85c to +125c 5 200 s lp oscillator 2t cy instruction cycle time (1) 100 160 ? ? ns ns t cy = 4/f osc , -40c to +85c t cy = 4/f osc , +85c to +125c 3t os l, t os h external clock in (osc1) high or low time 30 2.5 10 ? ? ? ns s ns xt oscillator lp oscillator hs oscillator 4t os r, t os f external clock in (osc1) rise or fall time ? ? ? 20 50 7.5 ns ns ns xt oscillator lp oscillator hs oscillator note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
? 2004 microchip technology inc. ds30491c-page 429 pic18f6585/8585/6680/8680 table 27-7: pll clock timing specifications (v dd = 4.2 to 5.5v) figure 27-7: clko and i/o timing param. no. sym characteristic min typ? max units conditions ?f osc oscillator frequency range 4 ? 10 mhz hs mode ?f sys on-chip vco system frequency 16 ? 40 mhz hs mode ?t rc pll start-up time (lock time) ? ? 2 ms ? ? clk clko stability (jitter) -2 ? +2 % ? data in ?typ? column is at 5v, 25 c, unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 27-5 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value
pic18f6585/8585/6680/8680 ds30491c-page 430 ? 2004 microchip technology inc. table 27-8: clko and i/o timing requirements figure 27-8: program memo ry read timing diagram param. no. symbol characteristic min typ max units conditions 10 t os h2 ck losc1 to clko ? 75 200 ns (1) 11 t os h2 ck hosc1 to clko ? 75 200 ns (1) 12 t ck r clko rise time ? 35 100 ns (1) 13 t ck f clko fall time ? 35 100 ns (1) 14 t ck l2 io vclko to port out valid ? ? 0.5 t cy + 20 ns (1) 15 t io v2 ck h port in valid before clko 0.25 t cy + 25 ? ? ns (1) 16 t ck h2 io i port in hold after clko 0??ns (1) 17 t os h2 io vosc1 (q1 cycle) to port out valid ? 50 150 ns 18 t os h2 io iosc1 (q2 cycle) to port input invalid (i/o in hold time) pic18fxx8x 100 ? ? ns 18a pic18lfxx8x 200 ? ? ns 19 t io v2 os h port input valid to osc1 (i/o in setup time) 0 ? ? ns 20 t io r port output rise time pic18fxx8x ? 10 25 ns 20a pic18lfxx8x ? ? 60 ns 21 t io f port output fall time pic18fxx8x ? 10 25 ns 21a pic18lfxx8x ? ? 60 ns 22? t inp int pin high or low time t cy ??ns 23? t rbp rb7:rb4 change int high or low time t cy ??ns 24? t rcp rc7:rc4 change int high or low time 20 ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode, where clko output is 4 x t osc . q1 q2 q3 q4 q1 q2 osc1 ale oe address data from external 166 160 165 161 151 162 163 ad<15:0> 167 168 155 address address 150 a<19:16> address 169 ba0 ce 171 171a 164
? 2004 microchip technology inc. ds30491c-page 431 pic18f6585/8585/6680/8680 table 27-9: program memory read timing requirements (v dd = 4.2 to 5.5v) figure 27-9: program memory write timing diagram param. no symbol characteristics min typ max units 150 t ad v2 al l address out valid to ale (address setup time) 0.25 t cy ? 10 ? ? ns 151 t al l2 adl ale to address out invalid (address hold time) 5??ns 155 t al l2 oe lale to oe 10 0.125 t cy ?ns 160 t ad z2 oe l ad high-z to oe (bus release to oe )0??ns 161 t oe h2 ad doe to ad driven 0.125 t cy ? 5 ? ? ns 162 t ad v2 oe h ls data valid before oe (data setup time) 20 ? ? ns 163 t oe h2 adl oe to data in invalid (data hold time) 0 ? ? ns 164 t al h2 al l ale pulse width ? 0.25 t cy ?ns 165 t oe l2 oe hoe pulse width 0.5 t cy ? 5 0.5 t cy ?ns 166 t al h2 al hale to ale (cycle time) ? 1 t cy ?ns 167 t acc address valid to data valid 0.75 t cy ? 25 ? ? ns 168 t oe oe to data valid ? 0.5 t cy ? 25 ns 169 t al l2 oe hale to oe 0.625 t cy ? 10 ? 0.625 t cy + 10 ns 171 t al h2 cs l chip select active to ale ??10ns 171a t ub l2 oe h ad valid to chip select active 0.25 t cy ? 20 ? ? ns q1 q2 q3 q4 q1 q2 osc1 ale address data 156 150 151 153 ad<15:0> address wrh or wrl ub or lb 157 154 157a address a<19:16> address ba0 166 ce 171 171a
pic18f6585/8585/6680/8680 ds30491c-page 432 ? 2004 microchip technology inc. table 27-10: program memory write timing requirements (v dd = 4.2 to 5.5v) figure 27-10: reset, watchdog timer, oscillator start-up timer and power-up timer timing param. no. symbol characteristics min typ max units 150 t ad v2 al l address out valid to ale (address setup time) 0.25 t cy ? 10 ? ? ns 151 t al l2 adl ale to address out invalid (address hold time) 5 ? ? ns 153 t wr h2 adl wrn to data out invalid (data hold time) 5 ? ? ns 154 t wr lwrn pulse width 0.5 t cy ? 5 0.5 t cy ?ns 156 t ad v2 wr h data valid before wrn (data setup time) 0.5 t cy ? 10 ? ? ns 157 t bs v2 wr l byte select valid before wrn (byte select setup time) 0.25 t cy ??ns 157a t wr h2 bs iwrn to byte select invalid (byte select hold time) 0.125 t cy ? 5 ? ? ns 166 t al h2 al hale to ale (cycle time) ? 0.25 t cy ?ns 171 t al h2 cs l chip enable active to ale ? ? 10 ns 171a t ub l2 oe h ad valid to chip enable active 0.25 t cy ? 20 ? ? ns v dd mclr internal por pwrt time-out osc time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 27-5 for load conditions.
? 2004 microchip technology inc. ds30491c-page 433 pic18f6585/8585/6680/8680 figure 27-11: brown-out reset timing table 27-11: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements figure 27-12: timer0 and timer1 external clock timings v dd bv dd 35 v bgap = 1.2v v irvst enable internal internal reference 36 reference voltage voltage stable param. no. symbol characteristic min typ max units conditions 30 t mc lmclr pulse width (low) 2 ? ? s 31 t wdt watchdog timer time-out period (no postscaler) 71833ms 32 t ost oscillation start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power up timer period 28 72 132 ms 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ?2? s 35 t bor brown-out reset pulse width 200 ? ? sv dd b vdd (see ) 36 t ivrst time for internal reference voltage to become stable ?2050 s 37 t lvd low-voltage detect pulse width 200 ? ? sv dd v lvd note: refer to figure 27-5 for load conditions. 46 47 45 48 41 42 40 t0cki t1oso/t1cki tmr0 or tmr1
pic18f6585/8585/6680/8680 ds30491c-page 434 ? 2004 microchip technology inc. table 27-12: timer0 and timer1 external clock requirements param. no. symbol characteristic min max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 t t 0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 n s or t cy + 40 n ?nsn = prescale value (1, 2, 4,..., 256) 45 t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler pic18fxx8x 10 ? ns pic18lfxx8x 25 ? ns asynchronous pic18fxx8x 30 ? ns pic18lfxx8x 50 ? ns 46 t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler pic18fxx8x 10 ? ns pic18lfxx8x 25 ? ns asynchronous pic18fxx8x 30 ? ns pic18lfxx8x tbd tbd ns 47 t t 1p t1cki input period synchronous greater of: 20 n s or t cy + 40 n ?nsn = prescale value (1, 2, 4, 8) asynchronous 60 ? ns f t 1 t1cki oscillator input frequency range dc 50 khz 48 t cke 2 tmr i delay from external t1cki clock edge to timer increment 2 t osc 7 t osc ?
? 2004 microchip technology inc. ds30491c-page 435 pic18f6585/8585/6680/8680 figure 27-13: capture/compare/pwm timings (all ccp modules) table 27-13: capture/compare/pwm requirements (all ccp modules) note: refer to figure 27-5 for load conditions. ccpx (capture mode) 50 51 52 ccpx 53 54 (compare or pwm mode) param. no. symbol characteristic min max units conditions 50 t cc l ccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler pic18fxx8x 10 ? ns pic18lfxx8x 20 ? ns 51 t cc h ccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler pic18fxx8x 10 ? ns pic18lfxx8x 20 ? ns 52 t cc p ccpx input period 3 t cy + 40 n ? ns n = prescale value (1,4 or 16) 53 t cc r ccpx output rise time pic18fxx8x ? 25 ns pic18lfxx8x ? 45 ns 54 t cc f ccpx output fall time pic18fxx8x ? 25 ns pic18lfxx8x ? 45 ns
pic18f6585/8585/6680/8680 ds30491c-page 436 ? 2004 microchip technology inc. figure 27-14: parallel slave port timing (pic18fxx8x) table 27-14: parallel slave port requirements (pic18fxx8x) note: refer to figure 27-5 for load conditions. re2/cs re0/rd re1/wr rd7:rd0 62 63 64 65 param. no. symbol characteristic min max units conditions 62 t dt v2 wr h data in valid before wr or cs (setup time) 20 25 ? ? ns ns extended temp. range 63 t wr h2 dt iwr or cs to data?in invalid (hold time) pic18fxx8x 20 ? ns pic18lfxx8x 35 ? ns 64 t rd l2 dt vrd and cs to data?out valid ? ? 80 90 ns ns extended temp. range 65 t rd h2 dt ird or cs to data?out invalid 10 30 ns 66 t ibf inh inhibit of the ibf flag bit being cleared from wr or cs ?3 t cy
? 2004 microchip technology inc. ds30491c-page 437 pic18f6585/8585/6680/8680 figure 27-15: example spi ma ster mode timing (cke = 0 ) table 27-15: example spi mode requirements (master mode, cke = 0 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - -1 msb in lsb in bit 6 - - - -1 note: refer to figure 27-5 for load conditions. param. no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18fxx8x ? 25 ns pic18lfxx8x ? 45 ns 76 t do f sdo data output fall time ? 25 ns 78 t sc r sck output rise time (master mode) pic18fxx8x ? 25 ns pic18lfxx8x ? 45 ns 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18fxx8x ? 50 ns pic18lfxx8x ? 100 ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used.
pic18f6585/8585/6680/8680 ds30491c-page 438 ? 2004 microchip technology inc. figure 27-16: example spi ma ster mode timing (cke = 1 ) table 27-16: example spi mode requirements (master mode, cke = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 81 71 72 74 75, 76 78 80 msb 79 73 msb in bit 6 - - - - - -1 lsb in bit 6 - - - -1 lsb note: refer to figure 27-5 for load conditions. param. no. symbol characteristic min max units conditions 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18fxx8x ? 25 ns pic18lfxx8x 45 ns 76 t do f sdo data output fall time ? 25 ns 78 t sc r sck output rise time (master mode) pic18fxx8x ? 25 ns pic18lfxx8x 45 ns 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18fxx8x ? 50 ns pic18lfxx8x 100 ns 81 t do v2 sc h, t do v2 sc l sdo data output setup to sck edge t cy ?ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used.
? 2004 microchip technology inc. ds30491c-page 439 pic18f6585/8585/6680/8680 figure 27-17: example spi slave mode timing (cke = 0 ) table 27-17: example spi mode requirements (slave mode timing, cke = 0 ) param. no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18fxx8x ? 25 ns pic18lfxx8x 45 ns 76 t do f sdo data output fall time ? 25 ns 77 t ss h2 do zss to sdo output high-impedance 10 50 ns 78 t sc r sck output rise time (master mode) pic18fxx8x ? 25 ns pic18lfxx8x 45 ns 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18fxx8x ? 50 ns pic18lfxx8x 100 ns 83 t sc h2 ss h, t sc l2 ss h ss after sck edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 77 78 79 80 79 78 sdi msb lsb bit 6 - - - - - -1 msb in bit 6 - - - -1 lsb in 83 note: refer to figure 27-5 for load conditions.
pic18f6585/8585/6680/8680 ds30491c-page 440 ? 2004 microchip technology inc. figure 27-18: example spi slave mode timing (cke = 1 ) table 27-18: example spi slave mode requirements (cke = 1 ) param. no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18fxx8x ? 25 ns pic18lfxx8x 45 ns 76 t do f sdo data output fall time ? 25 ns 77 t ss h2 do zss to sdo output high-impedance 10 50 ns 78 t sc r sck output rise time (master mode) pic18fxx8x ? 25 ns pic18lfxx8x ? 45 ns 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18fxx8x ? 50 ns pic18lfxx8x ? 100 ns 82 t ss l2 do v sdo data output valid after ss edge pic18fxx8x ? 50 ns pic18lfxx8x ? 100 ns 83 t sc h2 ss h, t sc l2 ss h ss after sck edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 82 sdi 74 75, 76 msb bit 6 - - - - - -1 lsb 77 msb in bit 6 - - - -1 lsb in 80 83 note: refer to figure 27-5 for load conditions.
? 2004 microchip technology inc. ds30491c-page 441 pic18f6585/8585/6680/8680 figure 27-19: i 2 c bus start/stop bits timing table 27-19: i 2 c bus start/stop bits requirements (slave mode) figure 27-20: i 2 c bus data timing note: refer to figure 27-5 for load conditions. 91 92 93 scl sda start condition stop condition 90 param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 27-5 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
pic18f6585/8585/6680/8680 ds30491c-page 442 ? 2004 microchip technology inc. table 27-20: i 2 c bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? s pic18fxx8x must operate at a minimum of 1.5 mhz 400 khz mode 0.6 ? s pic18fxx8x must operate at a minimum of 10 mhz ssp module 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? s pic18fxx8x must operate at a minimum of 1.5 mhz 400 khz mode 1.3 ? s pic18fxx8x must operate at a minimum of 10 mhz ssp module 1.5 t cy ? 102 t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sda and scl fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system but the requirement, t su : dat 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line. t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification) before the scl line is released.
? 2004 microchip technology inc. ds30491c-page 443 pic18f6585/8585/6680/8680 figure 27-21: master ssp i 2 c bus start/stop bits timing waveforms table 27-21: master ssp i 2 c bus start/stop bits requirements figure 27-22: master ssp i 2 c bus data timing note: refer to figure 27-5 for load conditions. 91 93 scl sda start condition stop condition 90 92 param. no. symbol characteristic min max units conditions 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ns 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 93 t hd : sto stop condition hold time 100 khz mode 2(t osc )(brg + 1) ? ns 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? note 1: maximum pin capacitance = 10 pf for all i 2 c pins. note: refer to figure 27-5 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
pic18f6585/8585/6680/8680 ds30491c-page 444 ? 2004 microchip technology inc. table 27-22: master ssp i 2 c bus data requirements param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 102 t r sda and scl rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 300 ns 103 t f sda and scl fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 100 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ms only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ms after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ms 1 mhz mode (1) tbd ? ns 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 1 mhz mode (1) tbd ? ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode (1) ??ns 110 t buf bus free time 100 khz mode 4.7 ? ms time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ms 1 mhz mode (1) tbd ? ms d102 c b bus capacitive loading ? 400 pf note 1: maximum pin capacitance = 10 pf for all i 2 c pins. 2: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system, but parameter #107 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line, parameter #102 + parameter #107 = 1000 + 250 = 1250 ns (for 100 khz mode), before the scl line is released.
? 2004 microchip technology inc. ds30491c-page 445 pic18f6585/8585/6680/8680 figure 27-23: usart synchronous transmission (master/slave) timing table 27-23: usart synchronous transmission requirements figure 27-24: usart synchronous receive (master/slave) timing table 27-24: usart synchronous receive requirements 121 121 120 122 rc6/tx/ck rc7/rx/dt pin pin note: refer to figure 27-5 for load conditions. param. no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (master & slave) clock high to data out valid pic18fxx8x ? 40 ns pic18lfxx8x ? 100 ns 121 t ckrf clock out rise time and fall time (master mode) pic18fxx8x ? 20 ns pic18lfxx8x ? 50 ns 122 t dtrf data out rise time and fall time pic18fxx8x ? 20 ns pic18lfxx8x ? 50 ns 125 126 rc6/tx/ck rc7/rx/dt pin pin note: refer to figure 27-5 for load conditions. param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (master & slave) data hold before ck (dt hold time) 10 ? ns 126 t ck l2 dtl data hold after ck (dt hold time) 15 ? ns
pic18f6585/8585/6680/8680 ds30491c-page 446 ? 2004 microchip technology inc. table 27-25: a/d converter characteristics: pic18f6585/8585/6680/8680 (industrial, extended) pic18lf6585/8585/6680/8680 (industrial) param no. symbol characteristic min typ max units conditions a01 n r resolution ? ? ? ? 10 tbd bit bit v ref = v dd 3.0v v ref = v dd < 3.0v a03 e il integral linearity error ? ? ? ? <1 tbd lsb lsb v ref = v dd 3.0v v ref = v dd < 3.0v a04 e dl differential linearity error ? ? ? ? <1 tbd lsb lsb v ref = v dd 3.0v v ref = v dd < 3.0v a05 e fs full-scale error ? ? ? ? <1 tbd lsb lsb v ref = v dd 3.0v v ref = v dd < 3.0v a06 e off offset error ? ? ? ? <1 tbd lsb lsb v ref = v dd 3.0v v ref = v dd < 3.0v a10 ? monotonicity guaranteed (3) ?v ss v ain v ref a20 v ref reference voltage (v refh ? v refl ) 0v ? ? v a20a 3v ? ? v for 10-bit resolution a21 v refh reference voltage high avss ? av dd + 0.3v v a22 v refl reference voltage low avss ? 0.3v ? av dd v a25 v ain analog input voltage av ss ? 0.3v ? v ref + 0.3v v a30 z ain recommended impedance of analog voltage source ??10.0k ? a40 i ad a/d conversion current (v dd ) pic18fxx8x ? 180 ? a average current consumption when a/d is on (note 1) pic18lfxx8x ? 90 ? a a50 i ref v ref input current (note 2) ? ? ? ? 5 150 a a during v ain acquisition. during a/d conversion cycle. note 1: when a/d is off, it will not consume any current other than minor leakage current. the power-down current spec includes any such leakage from the a/d module. v ref current is from ra2/an2/v ref - and ra3/an3/v ref + pins or av dd and av ss pins, whichever is selected as reference input. 2: vss v ain v ref 3: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes.
? 2004 microchip technology inc. ds30491c-page 447 pic18f6585/8585/6680/8680 figure 27-25: a/d conversion timing table 27-26: a/d conversion requirements 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 987 21 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns) which also disconnects the holding capacitor from the analog input. . . . . . . t cy param. no. symbol characteristic min max units conditions 130 t ad a/d clock period pic18fxx8x 1.6 20 (5) st osc based, v ref 3.0v pic18lfxx8x 3.0 20 (5) st osc based, v ref full range pic18fxx8x 2.0 6.0 s a/d rc mode pic18lfxx8x 3.0 9.0 s a/d rc mode 131 t cnv conversion time (not including acquisition time) (note 1) 11 12 t ad 132 t acq acquisition time (note 3) 15 10 ? ? s s -40 c te m p +125 c 0 c tem p +125 c 135 t swc switching time from convert sample ? (note 4) 136 t amp amplifier settling time (note 2) 1? s this may be used if the ?new? input voltage has not changed by more than 1 lsb (i.e., 5 mv @ 5.12v) from the last sampled voltage (as stated on c hold ). note 1: adres register may be read on the following t cy cycle. 2: see section 19.0 ?10-bit analog-to-digital converter (a/d) module? for minimum conditions when input voltage has changed more than 1 lsb. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (av dd to av ss , or av ss to av dd ). the source impedance ( r s ) on the input channels is 50 ? . 4: on the next q4 cycle of the device clock. 5: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider.
pic18f6585/8585/6680/8680 ds30491c-page 448 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 449 pic18f6585/8585/6680/8680 28.0 dc and ac characteristics graphs and tables ?typical? represents the mean of the distribution at 25 c. ?maximum? or ?minimum? represents (mean + 3 ) or (mean ? 3 ) respectively, where is a standard deviation, over the whole temperature range. figure 28-1: typical i dd vs. f osc over v dd (hs mode) figure 28-2: maximum i dd vs. f osc over v dd (hs mode) note: the graphs and tables provided following this note are a statistical summary based on a limited number of samples and are provided for informational purposes only. the performance characteristics listed herein are not tested or guaranteed. in some graphs or tables, the data presented may be outside the specified operating range (e.g., outside specified power supply range) and therefore, outside the warranted range. 0 4 8 12 16 20 24 28 32 36 40 4 8 12 16 20 24 28 32 36 40 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c) 0 4 8 12 16 20 24 28 32 36 40 44 48 4 8 12 16 20 24 28 32 36 40 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c)
pic18f6585/8585/6680/8680 ds30491c-page 450 ? 2004 microchip technology inc. figure 28-3: typical i dd vs. f osc over v dd (hs/pll mode) figure 28-4: maximum i dd vs. f osc over v dd (hs/pll mode) 0 4 8 12 16 20 24 28 32 36 40 45678910 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c) 0 5 10 15 20 25 30 35 40 45 45678910 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c)
? 2004 microchip technology inc. ds30491c-page 451 pic18f6585/8585/6680/8680 figure 28-5: typical i dd vs. f osc over v dd (xt mode) figure 28-6: maximum i dd vs. f osc over v dd (xt mode) 0 1 2 3 4 5 00.511.522.533.54 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 1 2 3 4 5 6 7 00.511.522.533.54 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic18f6585/8585/6680/8680 ds30491c-page 452 ? 2004 microchip technology inc. figure 28-7: typical i dd vs. f osc over v dd (lp mode) figure 28-8: maximum i dd vs. f osc over v dd (lp mode) 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 20 30 40 50 60 70 80 90 100 f osc (khz) idd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 1 2 3 4 5 6 20 30 40 50 60 70 80 90 100 f osc (khz) idd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2004 microchip technology inc. ds30491c-page 453 pic18f6585/8585/6680/8680 figure 28-9: typical i dd vs. f osc over v dd (ec mode) figure 28-10: maximum i dd vs. f osc over v dd (ec mode) 0 4 8 12 16 20 24 28 32 36 40 4 8 12 16 20 24 28 32 36 40 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v 4.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c) 0 4 8 12 16 20 24 28 32 36 40 44 48 4 8 12 16 20 24 28 32 36 40 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v 4.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +85c) minimum: mean ? 3 (-40c to +85c)
pic18f6585/8585/6680/8680 ds30491c-page 454 ? 2004 microchip technology inc. figure 28-11: typical and maximum i t1osc vs. v dd (timer1 as system clock) figure 28-12: average f osc vs. v dd for various r?s (rc mode, c = 20 pf, temp = 25c) 0 20 40 60 80 100 120 140 160 180 200 220 240 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i dd (ua) typ (25c) max (70c) typical: statistical mean @ 25c maximum: mean + 3 (-10c to +70c) minimum: mean ? 3 (-10c to +70c) 0 1,000 2,000 3,000 4,000 5,000 6,000 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (khz) 3.3k ? 5.1k ? 10k ? 100k ? operation above 4mhz is not recomended. 3.3k ? 100 k ? 10 k ? 5.1 k ? 3.3 k ?
? 2004 microchip technology inc. ds30491c-page 455 pic18f6585/8585/6680/8680 figure 28-13: average f osc vs. v dd for various r?s (rc mode, c = 100 pf, temp = 25c) figure 28-14: average f osc vs. v dd for various r?s (rc mode, c = 300 pf, temp = 25c) 100 k 0 200 400 600 800 1,000 1,200 1,400 1,600 1,800 2,000 2,200 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (khz) 3.3k ? 5.1k ? 10k ? 100k ? 3.3 k ? 5.1 k ? 10 k ? 100 k ? 0 100 200 300 400 500 600 700 800 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3k ? 5.1k ? 10k ? 100k ? 3.3 k ? 5.1 k ? 10 k ? 100 k ?
pic18f6585/8585/6680/8680 ds30491c-page 456 ? 2004 microchip technology inc. figure 28-15: i pd vs. v dd (sleep mode, all peripherals disabled) figure 28-16: typical and maximum ? i bor vs. v dd over temperature, v bor = 2.00v-2.16v 0.01 0.1 1 10 100 1000 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd (ua) max (-40c to +125c) typ (25c) max (85c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 50 100 150 200 250 300 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i dd (ua) max (+125c) max (+85c) typ (+25c) device held in reset device in sleep typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2004 microchip technology inc. ds30491c-page 457 pic18f6585/8585/6680/8680 figure 28-17: i t 1 osc vs. v dd (sleep mode, timer1 and oscillator enabled) figure 28-18: i pd vs. v dd (sleep mode, wdt enabled) 0 10 20 30 40 50 60 70 80 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd (ua) typ (25c) max (70c) typical: statistical mean @ 25c maximum: mean + 3 (-10c to +70c) minimum: mean ? 3 (-10c to +70c) 0.1 1 10 100 1000 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd (ua) max (-40c to +125c) typ (25c) max (85c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic18f6585/8585/6680/8680 ds30491c-page 458 ? 2004 microchip technology inc. figure 28-19: typical, minimum and maximum wdt period vs. v dd figure 28-20: ? i lvd vs. v dd over temperature, v lvd = 4.5-4.78v 0 5 10 15 20 25 30 35 40 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) w dt period (ms) max (125c) min (-40c) typ (25c) max (85c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 50 100 150 200 250 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i dd ( a) max (125c) typ (25c) max (125c) typ (25c) lvdif is set by hardware lvdif can be cleared by firmware lvdif state is unknown typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2004 microchip technology inc. ds30491c-page 459 pic18f6585/8585/6680/8680 figure 28-21: typical, minimum and maximum v oh vs. i oh (v dd = 5v, -40 c to +125 c) figure 28-22: typical, minimum and maximum v oh vs. i oh (v dd = 3v, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 0 5 10 15 20 25 i oh (-ma) v oh (v) typ (25c) max min max typ (+25c) min 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i oh (-ma) v oh (v) typ (25c) max min typ (+25c) min max
pic18f6585/8585/6680/8680 ds30491c-page 460 ? 2004 microchip technology inc. figure 28-23: typical and maximum v ol vs. i ol (v dd = 5v, -40 c to +125 c) figure 28-24: typical and maximum v ol vs. i ol (v dd = 3v, -40 c to +125 c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 0 5 10 15 20 25 i ol (-ma) v ol (v) max typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) typ (+25c) max 0.0 0.5 1.0 1.5 2.0 2.5 0 5 10 15 20 25 i ol (-ma) v ol (v) max typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) typ (+25c) max
? 2004 microchip technology inc. ds30491c-page 461 pic18f6585/8585/6680/8680 figure 28-25: minimum and maximum v in vs. v dd (st input, -40 c to +125 c) figure 28-26: minimum and maximum v in vs. v dd (ttl input, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v ih max v ih min v il max v il min typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v th (max) v th (min) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic18f6585/8585/6680/8680 ds30491c-page 462 ? 2004 microchip technology inc. figure 28-27: minimum and maximum v in vs. v dd (i 2 c input, -40 c to +125 c) figure 28-28: a/d nonlinearity vs. v refh (v dd = v refh , -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v ih max v ih min v il max v il min typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) v il max 0 0.5 1 1.5 2 2.5 3 3.5 4 22.533.544.555.5 v dd and v refh (v) differential or integral nonlinearity (lsb) -40c 25c 85c 125c -40c +25c +85c +125c
? 2004 microchip technology inc. ds30491c-page 463 pic18f6585/8585/6680/8680 figure 28-29: a/d non-linearity vs. v refh (v dd = 5v, -40 c to +125 c) 0 0.5 1 1.5 2 2.5 3 22.533.544.555.5 v refh (v) differential or integral nonlinearilty (lsb) max (-40c to 125c) typ (25c) typ (+25c) max (-40c to +125c)
pic18f6585/8585/6680/8680 ds30491c-page 464 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 465 pic18f6585/8585/6680/8680 29.0 packaging information 29.1 package marking information 68-lead plcc xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic18f6680-i/l 0410017 64-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example pic18f6680 -i/pt 0410017 80-lead tqfp xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic18f8680-e /pt 0410017 legend: xx...x customer specific information* y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line thus limiting the number of available characters for customer specific information. * standard picmicro device marking consists of microchip part number, year code, week code, and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price.
pic18f6585/8585/6680/8680 ds30491c-page 466 ? 2004 microchip technology inc. 29.2 package details the following sections give the technical details of the packages. 64-lead plastic thin quad flatpack (pt) 10x10x1 mm body, 1.0/0.10 mm lead form (tqfp) * controlling parameter notes: dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-026 drawing no. c04-085 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 0.27 0.22 0.17 .011 .009 .007 b lead width 0.23 0.18 0.13 .009 .007 .005 c lead thickness 16 16 n1 pins per side 10.10 10.00 9.90 .398 .394 .390 d1 molded package length 10.10 10.00 9.90 .398 .394 .390 e1 molded package width 12.25 12.00 11.75 .482 .472 .463 d overall length 12.25 12.00 11.75 .482 .472 .463 e overall width 7 3.5 0 7 3.5 0 foot angle 0.75 0.60 0.45 .030 .024 .018 l foot length 0.25 0.15 0.05 .010 .006 .002 a1 standoff 1.05 1.00 0.95 .041 .039 .037 a2 molded package thickness 1.20 1.10 1.00 .047 .043 .039 a overall height 0.50 .020 p pitch 64 64 n number of pins max nom min max nom min dimension limits millimeters* inches units c 2 1 n d d1 b p #leads=n1 e1 e a2 a1 a l ch x 45 (f) footprint (reference) (f) .039 1.00 pin 1 corner chamfer ch .025 .035 .045 0.64 0.89 1.14 significant characteristic
? 2004 microchip technology inc. ds30491c-page 467 pic18f6585/8585/6680/8680 68-lead plastic leaded chip carrier (l) ? square (plcc) 10 5 0 10 5 0 mold draft angle bottom 10 5 0 10 5 0 mold draft angle top 0.53 0.51 0.33 .021 .020 .013 b lower lead width 0.81 0.74 0.66 .032 .029 .026 b1 upper lead width 0.33 0.27 0.20 .013 .011 .008 c lead thickness 17 17 n1 pins per side 23.62 23.37 22.61 .930 .920 .890 d2 footprint length 23.62 23.37 22.61 .930 .920 .890 e2 footprint width 24.33 24.23 24.13 .958 .954 .950 d1 molded package length 24.33 24.23 24.13 .958 .954 .950 e1 molded package width 25.27 25.15 25.02 .995 .990 .985 d overall length 25.27 25.15 25.02 .995 .990 .985 e overall width 0.25 0.13 0.00 .010 .005 .000 ch2 corner chamfer (others) 1.27 1.14 1.02 .050 .045 .040 ch1 corner chamfer 1 0.86 0.74 0.61 .034 .029 .024 a3 side 1 chamfer height 0.51 .020 a1 standoff a2 molded package thickness 4.57 4.39 4.19 .180 .173 .165 a overall height 1.27 .050 p pitch 68 n number of pins max nom min max nom min dimension limits millimeters inches* units a2 c e2 2 d d1 n #leads=n1 e e1 1 p b a3 a b1 32 d2 68 a1 .145 .153 .160 3.68 3.87 4.06 .028 .035 0.71 0.89 ch1 x 45 ch2 x 45 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-047 drawing no. c04-049 significant characteristic
pic18f6585/8585/6680/8680 ds30491c-page 468 ? 2004 microchip technology inc. 80-lead plastic thin quad flatpack (pt) 12x12x1 mm body, 1.0/0.10 mm lead form (tqfp) * controlling parameter notes: dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-026 drawing no. c04-092 1.10 1.00 .043 .039 1.14 0.89 0.64 .045 .035 .025 ch pin 1 corner chamfer 1.00 .039 (f) footprint (reference) (f) e e1 #leads=n1 p b d1 d n 1 2 c l a a1 a2 units inches millimeters* dimension limits min nom max min nom max number of pins n 80 80 pitch p .020 0.50 overall height a .047 1.20 molded package thickness a2 .037 .039 .041 0.95 1.00 1.05 standoff a1 .002 .004 .006 0.05 0.10 0.15 foot length l .018 .024 .030 0.45 0.60 0.75 foot angle 03.5 7 03.5 7 overall width e .541 .551 .561 13.75 14.00 14.25 overall length d .541 .551 .561 13.75 14.00 14.25 molded package width e1 .463 .472 .482 11.75 12.00 12.25 molded package length d1 .463 .472 .482 11.75 12.00 12.25 pins per side n1 20 20 lead thickness c .004 .006 .008 0.09 0.15 0.20 lead width b .007 .009 .011 0.17 0.22 0.27 mold draft angle top 5 10 15 5 10 15 mold draft angle bottom 5 10 15 5 10 15 ch x 45 significant characteristic
? 2004 microchip technology inc. ds30491c-page 469 pic18f6585/8585/6680/8680 appendix a: revision history revision a (february 2003) original data sheet for pic18f6585/8585/6680/8680 family. revision b (june 2003) this revision includes updates to the special function registers in table 4-2 and table 23-1 and minor corrections to the data sheet text. revision c (february 2004) this revision includes the dc and ac characteristics graphs and tables. the electrical specifications in section 27.0 ?electrical characteristics? have been updated and there have been minor corrections to the data sheet text. appendix b: device differences the differences between the devices listed in this data sheet are shown in table b-1. table b-1: device differences feature pic18f6585 pic18f6680 pic18f8585 pic18f8680 on-chip program memory (kbytes) 48 64 48 64 i/o ports ports a, b, c, d, e, f, g ports a, b, c, d, e, f, g ports a, b, c, d, e, f, g, h, j ports a, b, c, d, e, f, g, h, j a/d channels 12 12 16 16 external memory interface no no yes yes package types 64-pin tqfp, 68-pin plcc 64-pin tqfp, 68-pin plcc 80-pin tqfp 80-pin tqfp
pic18f6585/8585/6680/8680 ds30491c-page 470 ? 2004 microchip technology inc. appendix c: conversion considerations this appendix discusses the considerations for con- verting from previous versions of a device to the ones listed in this data sheet. typically, these changes are due to the differences in the process technology used. an example of this type of conversion is from a pic17c756 to a pic18f8720. not applicable appendix d: migration from mid-range to enhanced devices a detailed discussion of the differences between the mid-range mcu devices (i.e., pic16cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an716, ?migrating designs from pic16c74a/74b to pic18c442.? the changes discussed, while device specific, are generally applicable to all mid-range to enhanced device migrations. this application note is available as literature number ds00716.
? 2004 microchip technology inc. ds30491c-page 471 pic18f6585/8585/6680/8680 appendix e: migration from high-end to enhanced devices a detailed discussion of the migration pathway and differences between the high-end mcu devices (i.e., pic17cxxx) and the enhanced devices (i.e., pic18fxxxx) is provided in an726, ?pic17cxxx to pic18cxxx migration.? this application note is available as literature number ds00726.
pic18f6585/8585/6680/8680 ds30491c-page 472 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 473 pic18f6585/8585/6680/8680 index a a/d .................................................................................... 249 a/d converter interrupt, configuring ....................................................... 253 acquisition requirements ......................................... 254 acquisition time........................................................ 254 adcon0 register..................................................... 249 adcon1 register..................................................... 249 adcon2 register..................................................... 249 adresh register..................................................... 249 adresh/adresl registers ................................... 252 adresl register ..................................................... 249 analog port pins ....................................................... 152 analog port pins, configuring ....................................................... 255 associated register summary .......................................................... 257 automatic acquisition time....................................... 255 calculating minimum required acquisition time (example) .............................. 254 ccp2 trigger ............................................................ 256 configuring the module............................................. 253 conversion clock (t ad ) ............................................ 255 conversion requirements ........................................ 447 conversion status (go/done bit) ................................................. 252 conversions .............................................................. 256 converter characteristics ......................................... 446 minimum charging time........................................... 254 special event trigger (ccp)................................................................ 171 special event trigger (ccp2).............................................................. 256 v ref + and v ref - references ................................... 254 absolute maximum ratings .............................................. 413 ac (timing) characteristics .............................................. 426 load conditions for device timing specifications........................................ 427 parameter symbology .............................................. 426 temperature and voltage specifications.................................................... 427 timing conditions ..................................................... 427 ackstat status flag ...................................................... 219 adcon0 register............................................................. 249 go/done bit............................................................ 252 adcon1 register............................................................. 249 adcon2 register............................................................. 249 addlw ............................................................................. 371 addwf ............................................................................. 371 addwfc .......................................................................... 372 adresh register............................................................. 249 adresh/adresl registers ........................................... 252 adresl register ............................................................. 249 analog-to-digital converter. see a/d. andlw............................................................................. 372 andwf............................................................................. 373 assembler mpasm assembler .................................................. 407 auto-wake-up on sync break character ....................................................... 242 b baud rate generator ....................................................... 215 bc..................................................................................... 373 bcf .................................................................................. 374 bf status flag .................................................................. 219 bit timing configuration registers brgcon1................................................................ 340 brgcon2................................................................ 340 brgcon3................................................................ 340 block diagrams 16-bit byte select mode ............................................. 98 16-bit byte write mode ............................................... 96 16-bit word write mode.............................................. 97 a/d............................................................................ 252 analog input model................................................... 253 baud rate generator ............................................... 215 can buffers and protocol engine ............................ 276 capture mode operation .......................................... 170 comparator analog input model .......................................... 263 comparator i/o operating modes (diagram) .......................................................... 260 comparator output................................................... 262 comparator voltage reference................................ 266 compare mode operation ................................ 171, 176 enhanced pwm........................................................ 178 low-voltage detect (lvd)........................................ 270 low-voltage detect (lvd) with external input ................................................... 270 mssp (i 2 c master mode)......................................... 213 mssp (i 2 c mode)..................................................... 198 mssp (spi mode) .................................................... 189 on-chip reset circuit................................................. 33 pic18f6x8x architecture .......................................... 10 pic18f8x8x architecture .......................................... 11 pll ............................................................................. 25 port/lat/tris operation ...................................... 125 porta ra3:ra0 and ra5 pins.................................... 126 ra4/t0cki pin ................................................. 126 ra6 pin (when enabled as i/o)....................... 126 portb rb2:rb0 pins................................................... 129 rb3 pin ............................................................ 129 rb7:rb4 pins................................................... 128 portc (peripheral output override)........................................................... 131 portd and porte (parallel slave port).......................................... 152
pic18f6585/8585/6680/8680 ds30491c-page 474 ? 2004 microchip technology inc. portd in i/o port mode .......................................... 133 portd in system bus mode ................................... 134 porte in i/o mode .................................................. 137 porte in system bus mode.................................... 137 portf rf1/an6/c2out and rf2/an7/c1out pins .............................. 139 rf6:rf3 and rf0 pins..................................... 140 rf7 pin ............................................................. 140 portg rg0/cantx1 pin ............................................. 142 rg1/cantx2 pin ............................................. 143 rg2/canrx pin............................................... 143 rg3 pin ............................................................ 143 rg4/p1d pin .................................................... 144 rg5/mclr /v pp pin .......................................... 144 porth rh3:rh0 pins in i/o mode ............................... 146 rh3:rh0 pins in system bus mode..................................... 147 rh7:rh4 pins in i/o mode ............................... 146 portj rj4:rj0 pins in system bus mode..................................... 150 rj7:rj6 pins in system bus mode..................................... 150 portj in i/o mode................................................... 149 pwm (ccp module) ................................................. 173 reads from flash program memory ............................................................... 87 single comparator .................................................... 261 table read operation................................................. 83 table write operation ................................................. 84 table writes to flash program memory ............................................................... 89 timer0 in 16-bit mode ............................................... 156 timer0 in 8-bit mode ................................................. 156 timer1 ....................................................................... 160 timer1 (16-bit read/write mode) ............................. 160 timer2 ....................................................................... 163 timer3 ....................................................................... 165 timer3 in 16-bit read/write mode ............................ 165 usart receive ........................................................ 240 usart transmit....................................................... 238 voltage reference output buffer (example).................................... 267 watchdog timer........................................................ 356 bn ..................................................................................... 374 bnc................................................................................... 375 bnn................................................................................... 375 bnov ................................................................................ 376 bnz ................................................................................... 376 bor. see brown-out reset. bov................................................................................... 379 bra................................................................................... 377 break character (12-bit) transmit and receive ............................................... 243 brg. see baud rate generator. brown-out reset (bor) .............................................. 34, 345 bsf ................................................................................... 377 btfsc .............................................................................. 378 btfss............................................................................... 378 btg................................................................................... 379 bz...................................................................................... 380 c c compilers mplab c17 .............................................................. 408 mplab c18 .............................................................. 408 mplab c30 .............................................................. 408 call................................................................................. 380 capture (ccp module) ..................................................... 169 can message time-stamp ...................................... 170 ccp pin configuration.............................................. 169 ccprxh:ccprxl registers .................................... 169 software interrupt ..................................................... 170 timer1/timer3 mode selection................................. 169 capture, compare (ccp module), timer1 and timer3 associated registers ................................................ 172 capture/compare/pwm (ccp) ........................................ 167 capture mode. see capture (ccp module). ccp module ............................................................. 169 ccprxh register..................................................... 169 ccprxl register ..................................................... 169 compare mode. see compare (ccp module). interaction of ccp1 and ccp2 modules ................................................. 169 pwm mode. see pwm (ccp module). timer resources ...................................................... 169 capture/compare/pwm requirements ........................................................... 435 clko and i/o timing requirements ........................ 430, 431 clocking scheme/instruction cycle .................................... 56 clrf ................................................................................ 381 clrwdt .......................................................................... 381 code examples 16 x 16 signed multiply routine ............................... 108 16 x 16 unsigned multiply routine ........................... 108 8 x 8 signed multiply routine ................................... 107 8 x 8 unsigned multiply routine ............................... 107 changing between capture prescalers......................................................... 170 changing to configuration mode .............................. 281 data eeprom read ................................................ 103 data eeprom refresh routine............................... 104 data eeprom write ................................................ 103 erasing a flash program memory row ...................................................... 88 fast register stack .................................................... 56 how to clear ram (bank 1) using indirect addressing............................................. 79 initializing porta..................................................... 125 initializing portb..................................................... 128 initializing portc .................................................... 131 initializing portd .................................................... 133 initializing porte..................................................... 136 initializing portf..................................................... 139 initializing portg .................................................... 142 initializing porth .................................................... 146 initializing portj ..................................................... 149 loading the sspbuf (sspsr) register ............................................................ 192 reading a flash program memory word ..................................................... 87
? 2004 microchip technology inc. ds30491c-page 475 pic18f6585/8585/6680/8680 saving status, wreg and bsr registers in ram .............................................................. 124 transmitting a can message using banked method................................................. 289 transmitting a can message using win bits............................................................ 290 win and icode bits usage in interrupt service routine to access tx/rx buffers ................................................... 281 writing to flash program memory ........................ 90?91 code protection ................................................................ 345 comf ............................................................................... 382 comparator ....................................................................... 259 analog input connection considerations.................................................. 263 associated registers ................................................ 264 configuration............................................................. 260 effects of a reset...................................................... 263 interrupts................................................................... 262 operation .................................................................. 261 operation during sleep ............................................ 263 outputs ..................................................................... 261 reference ................................................................. 261 external signal.................................................. 261 internal signal ................................................... 261 response time......................................................... 261 comparator specifications................................................ 423 comparator voltage reference ................................................................. 265 accuracy and error ................................................... 266 associated registers ................................................ 267 configuring................................................................ 265 connection considerations....................................... 266 effects of a reset...................................................... 266 operation during sleep ............................................ 266 compare (ccp module) ................................................... 171 ccp pin configuration.............................................. 171 ccprx register........................................................ 171 software interrupt ..................................................... 171 special event trigger................................ 161, 166, 171 timer1/timer3 mode selection ........................................................... 171 compare (ccp2 module) special event trigger................................................ 256 configuration bits.............................................................. 345 configuration mode........................................................... 328 control registers eecon1 and eecon2 .............................................. 84 tablat (table latch) register .............................................................. 86 tblptr (table pointer) register .............................................................. 86 conversion considerations ............................................... 470 cpfseq ........................................................................... 382 cpfsgt ........................................................................... 383 cpfslt ............................................................................ 383 d data eeprom memory associated registers................................................ 105 eeadrh eeadr register pair ....................................... 101 eecon1 register .................................................... 101 eecon2 register .................................................... 101 operation during code-protect .................................................... 104 protection against spurious write .................................................. 104 reading .................................................................... 103 using ........................................................................ 104 write verify ............................................................... 104 writing to .................................................................. 103 data memory ...................................................................... 59 general purpose registers ........................................ 59 map for pic18fxx80/xx85 devices............................................................... 60 special function registers......................................... 59 daw ................................................................................. 384 dc and ac characteristics graphs and tables ................................................... 449 dc characteristics pic18fxx8x (industrial and extended), pic18lfxx8x (industrial)......................................................... 421 power-down and supply current.................................................. 417 supply voltage ......................................................... 416 dcfsnz ........................................................................... 385 decf ................................................................................ 384 decfsz ........................................................................... 385 demonstration boards picdem 1................................................................. 410 picdem 17............................................................... 411 picdem 18r ............................................................ 411 picdem 2 plus......................................................... 410 picdem 3................................................................. 410 picdem 4................................................................. 410 picdem lin ............................................................. 411 picdem usb ........................................................... 411 picdem.net internet/ ethernet ............................................................ 410 development support ....................................................... 407 device differences............................................................ 469 device features.................................................................... 9 device overview................................................................... 9 direct addressing ............................................................... 78 disable mode.................................................................... 328
pic18f6585/8585/6680/8680 ds30491c-page 476 ? 2004 microchip technology inc. e ecan module ................................................................... 275 baud rate setting..................................................... 337 bit time partitioning .................................................. 337 bit timing configuration registers........................................................... 340 calculating t q , nominal bit rate and nominal bit time............................................... 338 can baud rate registers ........................................ 315 can control and status registers........................................................... 277 can controller register map ................................... 323 can i/o control register.......................................... 318 can interrupt registers............................................ 319 can interrupts .......................................................... 342 acknowledge..................................................... 343 bus activity wake-up ........................................ 343 bus-off.............................................................. 343 code bits .......................................................... 342 error .................................................................. 343 message error .................................................. 343 receive ............................................................. 343 receiver bus passive ....................................... 343 receiver overflow............................................. 343 receiver warning ............................................. 343 transmit ............................................................ 342 transmitter bus passive ................................... 343 transmitter warning ......................................... 343 can message buffers .............................................. 331 dedicated receive............................................ 331 dedicated transmit........................................... 331 programmable auto-rtr ................................. 332 programmable transmit/receive ...................................... 331 can message transmission .................................... 332 aborting............................................................. 332 initiating............................................................. 332 priority............................................................... 333 can modes of operation .......................................... 328 can registers .......................................................... 277 configuration mode................................................... 328 dedicated can receive buffer registers ................................................ 291 dedicated can transmit buffer registers ................................................ 285 disable mode ............................................................ 328 error detection .......................................................... 341 acknowledge..................................................... 341 bit...................................................................... 341 crc .................................................................. 341 error modes and counters................................ 341 error states....................................................... 341 form.................................................................. 341 stuff bit ............................................................. 341 error modes state (diagram) .................................... 342 error recognition mode ............................................ 330 filter-mask truth (table)............................................ 335 functional modes...................................................... 330 mode 0 - legacy mode ..................................... 330 mode 1 - enhanced legacy mode ............................................ 330 mode 2 - enhanced fifo mode................................................ 331 information processing time (ipt).................................................................. 338 lengthening a bit period .......................................... 339 listen only mode...................................................... 330 loopback mode ........................................................ 330 message acceptance filters and masks ................................................ 306, 335 message acceptance mask and filter operation................................................. 336 message reception .................................................. 334 enhanced fifo mode ...................................... 335 priority .............................................................. 334 time-stamping ................................................. 335 normal mode ............................................................ 328 oscillator tolerance.................................................. 340 overview................................................................... 275 phase buffer segments............................................ 338 programmable tx/rx and auto-rtr buffers ............................................. 297 programming time segments .................................. 340 propagation segment ............................................... 338 sample point ............................................................ 338 shortening a bit period............................................. 340 synchronization ........................................................ 339 hard.................................................................. 339 resynchronization ............................................ 339 rules ................................................................ 339 synchronization segment......................................... 338 time quanta ............................................................. 338 electrical characteristics .................................................. 413 enhanced capture/compare/pwm (eccp) ..................................................................... 175 outputs ..................................................................... 176 enhanced pwm mode. see pwm (eccp module). enhanced universal synchronous asynchronous receiver transmitter (usart) ................................................ 229 errata .................................................................................... 7 error recognition mode.................................................... 328 evaluation and programming tools.................................. 411 example spi mode requirements (master mode, cke = 0)........................................... 437 example spi mode requirements (master mode, cke = 1)........................................... 438 example spi mode requirements (slave mode, cke = 0)............................................. 439 example spi slave mode requirements (cke = 1).................................................................. 440 external clock timing requirements ........................................................... 428 external memory interface.................................................. 93 16-bit byte select mode.............................................. 98 16-bit byte write mode ............................................... 96 16-bit mode................................................................. 96 16-bit mode timing ..................................................... 99 16-bit word write mode.............................................. 97 pic18f8x8x external bus - i/o port functions............................................... 95 program memory modes ............................................ 93
? 2004 microchip technology inc. ds30491c-page 477 pic18f6585/8585/6680/8680 f firmware instructions........................................................ 365 flash program memory ...................................................... 83 associated registers .................................................. 92 control registers ........................................................ 84 erase sequence ......................................................... 88 erasing........................................................................ 88 operation during code protection............................................................ 92 reading....................................................................... 87 table pointer boundaries based on operation......................... 86 table pointer boundaries ........................................... 86 table reads and table writes ................................... 83 write sequence .......................................................... 90 writing to..................................................................... 89 protection against spurious writes.......................................................... 92 unexpected termination..................................... 92 write verify ......................................................... 92 g general call address support .......................................... 212 goto ............................................................................... 386 h hardware multiplier ........................................................... 107 introduction ............................................................... 107 operation .................................................................. 107 performance comparison (table)................................................................ 107 i i/o ports ............................................................................ 125 i 2 c bus data requirements (slave mode)............................................................. 442 i 2 c bus start/stop bits requirements (slave mode)............................................................. 441 i 2 c mode general call address support .................................. 212 master mode operation .......................................................... 214 read/write bit information (r/w bit) ................................................... 202, 203 serial clock (rc3/sck/scl).................................... 203 id locations .............................................................. 345, 362 incf.................................................................................. 386 incfsz ............................................................................. 387 in-circuit debugger ........................................................... 362 resources (table)...................................................... 362 in-circuit serial programming (icsp) ............................................................... 345, 362 indirect addressing indf and fsr registers ............................................ 79 operation .................................................................... 79 indirect file operand .......................................................... 59 infsnz ............................................................................. 387 instruction flow/pipelining .................................................. 57 instruction format ............................................................. 367 instruction set................................................................... 365 addlw..................................................................... 371 addwf .................................................................... 371 addwfc.................................................................. 372 andlw..................................................................... 372 andwf .................................................................... 373 bc............................................................................. 373 bcf .......................................................................... 374 bn............................................................................. 374 bnc .......................................................................... 375 bnn .......................................................................... 375 bnov ....................................................................... 376 bnz .......................................................................... 376 bov .......................................................................... 379 bra .......................................................................... 377 bsf........................................................................... 377 btfsc...................................................................... 378 btfss ...................................................................... 378 btg .......................................................................... 379 bz ............................................................................. 380 call......................................................................... 380 clrf ........................................................................ 381 clrwdt .................................................................. 381 comf ....................................................................... 382 cpfseq................................................................... 382 cpfsgt ................................................................... 383 cpfslt.................................................................... 383 daw ......................................................................... 384 dcfsnz ................................................................... 385 decf........................................................................ 384 decfsz ................................................................... 385 goto ....................................................................... 386 incf ......................................................................... 386 incfsz..................................................................... 387 infsnz..................................................................... 387 iorlw...................................................................... 388 iorwf...................................................................... 388 lfsr ........................................................................ 389 movf ....................................................................... 389 movff ..................................................................... 390 movlb ..................................................................... 390 movlw .................................................................... 391 movwf.................................................................... 391 mullw..................................................................... 392 mulwf .................................................................... 392 negf........................................................................ 393 nop.......................................................................... 393 pop .......................................................................... 394 push........................................................................ 394 rcall ...................................................................... 395 reset...................................................................... 395 retfie..................................................................... 396 retlw ..................................................................... 396 return................................................................... 397 rlcf ........................................................................ 397 rlncf...................................................................... 398 rrcf........................................................................ 398 rrncf .................................... ................................. 399 setf ........................................................................ 399
pic18f6585/8585/6680/8680 ds30491c-page 478 ? 2004 microchip technology inc. sleep ...................................................................... 400 subfwp................................................................... 400 sublw ..................................................................... 401 subwf ..................................................................... 401 subwfb................................................................... 402 swapf ..................................................................... 402 tblrd ...................................................................... 403 tblwt ...................................................................... 404 tstfsz .................................................................... 405 xorlw ..................................................................... 405 xorwf..................................................................... 406 summary table......................................................... 368 int interrupt (rb0/int). see interrupt sources. intcon registers ............................................................ 111 inter-integrated circuit. see i 2 c. interrupt sources............................................................... 345 a/d conversion complete ........................................ 253 capture complete (ccp).......................................... 170 compare complete (ccp)........................................ 171 ecan module ........................................................... 342 int0 .......................................................................... 124 interrupt-on-change (rb7:rb4)......................................................... 128 portb, interrupt-on-change ................................... 124 rb0/int pin, external ............................................... 124 tmr0 ........................................................................ 124 tmr0 overflow ......................................................... 157 tmr1 overflow ................................................. 159, 161 tmr2 to pr2 match ................................................. 163 tmr2 to pr2 match (pwm) ..................... 162, 173, 177 tmr3 overflow ................................................. 164, 166 interrupts ........................................................................... 109 context saving during interrupts........................................................... 124 control registers ...................................................... 111 enable registers....................................................... 117 flag registers........................................................... 114 logic (diagram) ......................................................... 110 priority registers....................................................... 120 reset control registers............................................ 123 interrupts, flag bits ccp flag (ccpxif bit) ............................. 169, 170, 171 iorlw .............................................................................. 388 iorwf .............................................................................. 388 ipr registers .................................................................... 120 l lfsr ................................................................................. 389 listen only mode .............................................................. 328 look-up tables computed goto ........................................................ 58 table reads/table writes .......................................... 58 loopback mode................................................................. 328 low-voltage detect........................................................... 269 characteristics .......................................................... 424 converter characteristics ......................................... 424 effects of a reset...................................................... 273 operation .................................................................. 272 current consumption........................................ 273 during sleep ..................................................... 273 reference voltage set point............................. 273 typical application .................................................... 269 low-voltage icsp programming ...................................... 363 lvd. see low-voltage detect. m master ssp i 2 c bus data requirements................................................... 444 master ssp i 2 c bus start/stop bits requirements ........................................................... 443 master synchronous serial port (mssp). see mssp. memory organization data memory .............................................................. 59 pic18f8x8x program memory modes ...................... 51 extended microcontroller.................................... 51 microcontroller .................................................... 51 microprocessor ................................................... 51 microprocessor with boot block .................................................. 51 program memory ........................................................ 51 memory programming requirements............................... 425 migration from high-end to enhanced devices.................................................... 471 migration from mid-range to enhanced devices.................................................... 470 movf ............................................................................... 389 movff ............................................................................. 390 movlb ............................................................................. 390 movlw ............................................................................ 391 movwf ............................................................................ 391 mplab asm30 assembler, linker, librarian ........................................................ 408 mplab icd 2 in-circuit debugger ................................... 409 mplab ice 2000 high-performance universal in-circuit emulator .................................................... 409 mplab ice 4000 high-performance universal in-circuit emulator .................................................... 409 mplab integrated development environment software .............................................. 407 mplab pm3 device programmer .................................... 409 mplink object linker/ mplib object librarian............................................. 408 mssp................................................................................ 189 ack pulse ........................................................ 202, 203 clock stretching........................................................ 208 10-bit slave receive mode (sen = 1).................................................. 208 10-bit slave transmit mode.............................. 208 7-bit slave receive mode (sen = 1).................................................. 208 7-bit slave transmit mode................................ 208 clock synchronization and the ckp bit ............................................................. 209 control registers (general)....................................... 189 i 2 c mode .................................................................. 198 acknowledge sequence timing ....................... 222 baud rate generator ....................................... 215 bus collision during a repeated start condition.................................. 226 bus collision during a start condition.......................................... 224 bus collision during a stop condition .......................................... 227 clock arbitration ............................................... 216 effect of a reset ............................................... 223 i 2 c clock rate w/brg ..................................... 215
? 2004 microchip technology inc. ds30491c-page 479 pic18f6585/8585/6680/8680 master mode ..................................................... 213 reception.................................................. 219 repeated start condition timing ............................................... 218 transmission ............................................ 219 master mode start condition ............................ 217 module operation ............................................. 202 multi-master communication, bus collision and arbitration ................................................. 223 multi-master mode ............................................ 223 registers........................................................... 198 slave mode ....................................................... 202 slave mode, addressing ................................... 202 slave mode, reception..................................... 203 slave mode, transmission ............................... 203 sleep operation ................................................ 223 stop condition timing ...................................... 222 i 2 c mode. see i 2 c. overview ................................................................... 189 spi mode .................................................................. 189 associated registers ........................................ 197 bus mode compatibility .................................... 197 effects of a reset ............................................. 197 enabling spi i/o ............................................... 193 master mode ..................................................... 194 operation .......................................................... 192 slave mode ....................................................... 195 slave select synchronization ........................................ 195 sleep operation ................................................ 197 spi clock .......................................................... 194 typical connection ........................................... 193 spi mode. see spi. sspbuf register ..................................................... 194 sspsr register ....................................................... 194 mssp module spi master/slave connection ................................... 193 mullw ............................................................................. 392 mulwf ............................................................................. 392 n negf ................................................................................ 393 nop .................................................................................. 393 normal operation mode.................................................... 328 o opcode field descriptions ................................................ 366 option_reg register psa bit...................................................................... 157 t0cs bit.................................................................... 157 t0ps2:t0ps0 bits .................................................... 157 t0se bit.................................................................... 157 oscillator configuration....................................................... 23 ec ............................................................................... 23 ecio ........................................................................... 23 ecio+pll................................................................... 23 ecio+spll ................................................................ 23 hs ............................................................................... 23 hs+pll ...................................................................... 23 hs+spll .................................................................... 23 lp................................................................................ 23 rc............................................................................... 23 rcio ........................................................................... 23 xt ............................................................................... 23 oscillator selection ........................................................... 345 oscillator start-up timer (ost) .................................. 34, 345 oscillator switching feature system clock switch bit............................................. 27 oscillator, timer1.............................................. 159, 161, 166 oscillator, timer3.............................................................. 164 oscillator, wdt................................................................. 355 p packaging ......................................................................... 465 details....................................................................... 466 marking..................................................................... 465 parallel slave port (psp).......................................... 133, 152 associated registers................................................ 154 re0/rd /ad8 pin ...................................................... 152 re1/wr /ad9 pin ..................................................... 152 re2/cs /ad10 pin .................................................... 152 select (pspmode bit) ..................................... 133, 152 parallel slave port requirements (pic18fxx8x).......................................................... 436 phase locked loop (pll) .................................................. 25 pickit 1 flash starter kit .................................................. 411 picstart plus development programmer.............................................................. 410 pie registers.................................................................... 117 pin functions av dd ........................................................................... 21 av ss ........................................................................... 21 osc1/clki................................................................. 12 osc2/clko/ra6 ....................................................... 12 ra0/an0..................................................................... 13 ra1/an1..................................................................... 13 ra2/an2/v ref - .......................................................... 13 ra3/an3/v ref + ......................................................... 13 ra4/t0cki ................................................................. 13 ra5/an4/lvdin ......................................................... 13 ra6............................................................................. 13 rb0/int0.................................................................... 14 rb1/int1.................................................................... 14 rb2/int2.................................................................... 14 rb3/int3/ccp2 ......................................................... 14 rb4/kbi0.................................................................... 14 rb5/kbi1/pgm........................................................... 14 rb6/kbi2/pgc ........................................................... 14 rb7/kbi3/pgd ........................................................... 14 rc0/t1oso/t13cki .................................................. 15 rc1/t1osi/ccp2 ...................................................... 15 rc2/ccp1/p1a .......................................................... 15 rc3/sck/scl ............................................................ 15 rc4/sdi/sda ............................................................. 15 rc5/sdo.................................................................... 15 rc6/tx/ck................................................................. 15 rc7/rx/dt................................................................. 15 rd0/psp0/ad0 .......................................................... 16 rd1/psp1/ad1 .......................................................... 16 rd2/psp2/ad2 .......................................................... 16 rd3/psp3/ad3 .......................................................... 16 rd4/psp4/ad4 .......................................................... 16 rd5/psp5/ad5 .......................................................... 16 rd6/psp6/ad6 .......................................................... 16 rd7/psp7/ad7 .......................................................... 16 re0/rd /ad8 .............................................................. 17 re1/wr /ad9.............................................................. 17
pic18f6585/8585/6680/8680 ds30491c-page 480 ? 2004 microchip technology inc. re2/cs /ad10 ............................................................. 17 re3/ad11 ................................................................... 17 re4/ad12 ................................................................... 17 re5/ad13/p1c ........................................................... 17 re6/ad14/p1b ........................................................... 17 re7/ccp2/ad15 ........................................................ 17 rf0/an5 ..................................................................... 18 rf1/an6/c2out ........................................................ 18 rf2/an7/c1out ........................................................ 18 rf3/an8/c2in+ .......................................................... 18 rf4/an9/c2in-........................................................... 18 rf5/an10/c1in+/cv ref ............................................ 18 rf6/an11/c1in-......................................................... 18 rf7/ss ....................................................................... 18 rg0/cantx1 ............................................................. 19 rg1/cantx2 ............................................................. 19 rg2/canrx ............................................................... 19 rg3............................................................................. 19 rg4/p1d..................................................................... 19 rg5/mclr /v pp .......................................................... 12 rh0/a16 ..................................................................... 20 rh1/a17 ..................................................................... 20 rh2/a18 ..................................................................... 20 rh3/a19 ..................................................................... 20 rh4/an12 ................................................................... 20 rh5/an13 ................................................................... 20 rh6/an14/p1c ........................................................... 20 rh7/an15/p1b ........................................................... 20 rj0/ale ...................................................................... 21 rj1/oe ....................................................................... 21 rj2/wrl ..................................................................... 21 rj3/wrh .................................................................... 21 rj4/ba0 ...................................................................... 21 rj5/ce ........................................................................ 21 rj6/lb ........................................................................ 21 rj7/ub ........................................................................ 21 v dd .............................................................................. 21 v ss .............................................................................. 21 pir registers .................................................................... 114 pll clock timing specifications....................................... 429 pll lock time-out .............................................................. 34 pointer, fsr........................................................................ 79 pop................................................................................... 394 por. see power-on reset. porta associated registers ................................................ 127 functions .................................................................. 127 lata register........................................................... 125 porta register ....................................................... 125 trisa register ......................................................... 125 portb associated registers ................................................ 130 functions .................................................................. 130 latb register........................................................... 128 portb register ....................................................... 128 rb0/int pin, external ............................................... 124 trisb register ......................................................... 128 portc associated registers ................................................ 132 functions .................................................................. 132 latc register .......................................................... 131 portc register ....................................................... 131 rc3/sck/scl pin .................................................... 203 trisc register......................................................... 131 portd ............................................................................. 152 associated registers ................................................ 135 functions .................................................................. 135 latd register .......................................................... 133 parallel slave port (psp) function............................................................ 133 portd register....................................................... 133 trisd register......................................................... 133 porte analog port pins ....................................................... 152 associated registers ................................................ 138 functions .................................................................. 138 late register .......................................................... 136 porte register ....................................................... 136 psp mode select (pspmode bit) ........................................ 133, 152 re0/rd /ad8 pin ...................................................... 152 re1/wr /ad9 pin...................................................... 152 re2/cs /ad10 pin..................................................... 152 trise register......................................................... 136 portf associated registers ................................................ 141 functions .................................................................. 141 latf register........................................................... 139 portf register ....................................................... 139 trisf register ......................................................... 139 portg associated registers ................................................ 145 functions .................................................................. 145 latg register .......................................................... 142 portg register....................................................... 142 trisg register ........................................................ 142 porth associated registers ................................................ 148 functions .................................................................. 148 lath register .......................................................... 146 porth register....................................................... 146 trish register......................................................... 146 portj associated registers ................................................ 151 functions .................................................................. 151 latj register ........................................................... 149 portj register........................................................ 149 trisj register ......................................................... 149 postscaler, wdt assignment (psa bit) ............................................... 157 rate select (t0ps2:t0ps0 bits) ......................................... 157 power-down mode. see sleep. power-on reset (por)............................................... 34, 345 power-up delays ................................................................ 31 power-up timer (pwrt) ............................................ 34, 345 prescaler timer2 ...................................................................... 177 prescaler, capture............................................................ 170 prescaler, timer0 ............................................................. 157 assignment (psa bit) ............................................... 157 rate select (t0ps2:t0ps0 bits) ......................................... 157 prescaler, timer2 ............................................................. 173 pro mate ii universal device programmer.............................................................. 409
? 2004 microchip technology inc. ds30491c-page 481 pic18f6585/8585/6680/8680 product identification system ........................................... 487 program counter pcl, pclath and pclatu registers............................................................. 56 program memory instructions.................................................................. 57 two-word ........................................................... 58 interrupt vector ........................................................... 51 map and stack for pic18f6585/8585............................................... 52 map and stack for pic18f6680/8680............................................... 52 memory access for pic18f8x8x modes ........................................... 52 memory maps for pic18f8x8x modes ........................................... 53 reset vector ............................................................... 51 program memory modes extended microcontroller ............................................ 93 microcontroller ............................................................ 93 microprocessor ........................................................... 93 microprocessor with boot block........................................................... 93 program memory write timing requirements............................................................ 432 program verification and code protection ........................................................ 359 associated registers ................................................ 359 configuration register protection.......................................................... 362 data eeprom code protection.......................................................... 362 memory code protection .......................................... 360 programming, device instructions .................................... 365 psp. see parallel slave port. push ................................................................................ 394 pwm (ccp module) ......................................................... 173 ccpr1h:ccpr1l registers.................................... 177 ccpr1l:ccpr1h registers.................................... 173 duty cycle......................................................... 173, 177 example frequencies/ resolutions ............................................... 174, 178 period................................................................ 173, 177 registers associated with pwm and timer2........................................................ 187 setup for pwm operation......................................... 174 tmr2 to pr2 match ................................. 162, 173, 177 pwm (ccp module) and timer2 associated registers ................................................ 174 pwm (eccp module) ....................................................... 177 effects of a reset...................................................... 187 enhanced pwm auto-shutdown .............................. 184 full-bridge application example ............................................................ 182 full-bridge mode....................................................... 181 direction change .............................................. 182 half-bridge mode ...................................................... 180 half-bridge output mode applications example ....................................... 180 output configurations ............................................... 177 output relationships (active-high state)............................................ 178 output relationships (active-low state) ............................................ 179 programmable dead-band delay............................. 184 pwm direction change (diagram)............................ 183 pwm direction change at near 100% duty cycle (diagram)........................................ 183 setup for operation .................................................. 187 start-up considerations............................................ 186 q q clock ..................................................................... 173, 177 r ram. see data memory. rc oscillator....................................................................... 24 rcall .............................................................................. 395 rcon register................................................................. 123 rcsta register spen bit................................................................... 229 register file........................................................................ 59 register file summary ................................................. 67?77 registers adcon0 (a/d control 0).......................................... 249 adcon1 (a/d control 1).......................................... 250 adcon2 (a/d control 2).......................................... 251 baudcon (baud rate control)............................... 232 bie0 (buffer interrupt enable 0) ............................... 322 bncon (tx/rx buffer n control, receive mode) ................................................. 297 bncon (tx/rx buffer n control, transmit mode) ................................................ 298 bndlc (tx/rx buffer n data length code in receive mode) .................................... 304 bndlc (tx/rx buffer n data length code in transmit mode) ................................... 305 bndm (tx/rx buffer n data field byte m in receive mode).............................................. 303 bndm (tx/rx buffer n data field byte m in transmit mode)............................................. 303 bneidh (tx/rx buffer n extended identifier, high byte in receive mode) ................................................. 301 bneidh (tx/rx buffer n extended identifier, high byte in transmit mode) ................................................ 301 bneidl (tx/rx buffer n extended identifier, low byte in receive mode) ................................................. 302 bneidl (tx/rx buffer n extended identifier, low byte in transmit mode) ................................................ 302 bnsidh (tx/rx buffer n standard identifier, high byte in receive mode) ................................................. 299 bnsidh (tx/rx buffer n standard identifier, high byte in transmit mode) ................................................ 299 bnsidl (tx/rx buffer n standard identifier, low byte in receive mode) ................................................. 300
pic18f6585/8585/6680/8680 ds30491c-page 482 ? 2004 microchip technology inc. bnsidl (tx/rx buffer n standard identifier, low byte in transmit mode)................................................. 300 brgcon1 (baud rate control 1) ............................ 315 brgcon2 (baud rate control 2) ............................ 316 brgcon3 (baud rate control 3) ............................ 317 bsel0 (buffer select 0)............................................ 305 cancon (can control) ........................................... 278 canstat (can status) ........................................... 279 ccp1con (ccp1 control) ............................... 167, 175 ccp2con (ccp2 control) ....................................... 168 ciocon (can i/o control) ...................................... 318 cmcon (comparator control) ................................. 259 comstat (can communication status)........................... 284 config1h (configuration 1 high) ........................... 347 config2h (configuration 2 high) ........................... 349 config2l (configuration 2 low)............................. 348 config3h (configuration 3 high) ........................... 350 config3l (configuration 3 low)............................. 349 config3l (configuration byte) ................................. 53 config4l (configuration 4 low)............................. 350 config5h (configuration 5 high) ........................... 351 config5l (configuration 5 low)............................. 351 config6h (configuration 6 high) ........................... 352 config6l (configuration 6 low)............................. 352 config7h (configuration 7 high) ........................... 353 config7l (configuration 7 low)............................. 353 cvrcon (comparator voltage reference control)............................................ 265 device id 1 ............................................................... 354 device id 2 ............................................................... 354 ecancon (enhanced can control) ....................... 283 eccp1as (eccp1 auto-shutdown control) ............................................................. 185 eccp1del (eccp1 delay) ..................................... 184 eecon1 (data eeprom control 1) .................................................... 85, 102 intcon (interrupt control) ....................................... 111 intcon2 (interrupt control 2).................................. 112 intcon3 (interrupt control 3).................................. 113 ipr1 (peripheral interrupt priority 1)........................................................... 120 ipr2 (peripheral interrupt priority 2)........................................................... 121 ipr3 (peripheral interrupt priority 3)................................................... 122, 321 lvdcon (lvd control) ............................................ 271 memcon (memory control)....................................... 94 osccon (oscillator control) ..................................... 27 pie1 (peripheral interrupt enable 1)........................................................... 117 pie2 (peripheral interrupt enable 2)........................................................... 118 pie3 (peripheral interrupt enable 3)................................................... 119, 320 pir1 (peripheral interrupt request 1) ........................................................ 114 pir2 (peripheral interrupt request 2) ........................................................ 115 pir3 (peripheral interrupt flag 3)............................................................... 319 pir3 (peripheral interrupt request 3) ........................................................ 116 pspcon (parallel slave port control)............................................................. 153 rcon (reset control).................................. 35, 82, 123 rcsta (receive status and control)............................................................. 231 rxb0con (receive buffer 0 control)............................................................. 291 rxb1con (receive buffer 1 control)............................................................. 293 rxbndlc (receive buffer n data length code) ........................................... 295 rxbndm (receive buffer n data field byte m)............................................ 296 rxbneidh (receive buffer n extended identifier, high byte)......................... 294 rxbneidl (receive buffer n extended identifier, low byte).......................... 295 rxbnsidh (receive buffer n standard indentifier, high byte) ....................... 294 rxbnsidl (receive buffer n standard identifier, low byte) .......................... 294 rxerrcnt (receive error count).......................... 296 rxfneidh (receive acceptance filter n extended identifier, high byte)......................................................... 307 rxfneidl (receive acceptance filter n extended identifier, low byte).......................................................... 307 rxfnsidh (receive acceptance filter n standard identifier filter, high byte)......................................................... 306 rxfnsidl (receive acceptance filter n standard identifier filter, low byte).......................................................... 306 rxmneidh (receive acceptance mask n extended identifier mask, high byte)......................................................... 308 rxmneidl (receive acceptance mask n extended identifier mask, low byte).......................................................... 308 rxmnsidh (receive acceptance mask n standard identifier mask, high byte)......................................................... 307 rxmnsidl (receive acceptance mask n standard identifier mask, low byte).......................................................... 308 sspcon1 (mssp control 1 in spi mode)..................................................... 191 sspcon2 (mssp control 2 in i 2 c mode) ..................................................... 201 sspstat (mssp status in spi mode).................................................... 190 status ......................................................................... 81 stkptr (stack pointer)............................................. 55 t0con (timer0 control) .......................................... 155 t1con (timer 1 control) ......................................... 159 t2con (timer2 control) .......................................... 162 t3con (timer3 control) .......................................... 164
? 2004 microchip technology inc. ds30491c-page 483 pic18f6585/8585/6680/8680 txbie (transmit buffers interrupt enable) ............................................... 322 txbncon (transmit buffer n control) ............................................................. 285 txbndlc (transmit buffer n data length code) ........................................... 288 txbndm (transmit buffer n data field byte m) ............................................ 287 txbneidh (transmit buffer n extended identifier, high byte) ......................... 286 txbneidl (transmit buffer n extended identifier, low byte) .......................... 287 txbnsidh (transmit buffer n standard identifier, high byte).......................... 286 txbnsidl (transmit buffer n standard identifier, low byte) .......................... 286 txerrcnt (transmit error count) ......................... 288 txsta (transmit status and control) ............................................................. 230 wdtcon (watchdog timer control) ............................................................. 355 reset .............................................................................. 395 reset........................................................................... 33, 345 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements................................ 433 retfie ............................................................................. 396 retlw ............................................................................. 396 return ........................................................................... 397 return address stack and associated registers ........................................... 55 stack pointer (stkptr) ............................................. 54 top-of-stack access................................................... 54 revision history ................................................................ 469 rlcf................................................................................. 397 rlncf .............................................................................. 398 rrcf ................................................................................ 398 rrncf ......................... .................................................... 399 s sck................................................................................... 189 sdi .................................................................................... 189 sdo .................................................................................. 189 serial clock, sck ............................................................. 189 serial data in, sdi ............................................................ 189 serial data out, sdo........................................................ 189 serial peripheral interface. see spi. setf ................................................................................. 399 slave select, ss ............................................................... 189 sleep .............................................................................. 400 sleep ......................................................................... 345, 357 software simulator (mplab sim) ............................................................ 408 software simulator (mplab sim30) ........................................................ 408 special event trigger. see compare. special features of the cpu ............................................ 345 configuration registers .................................... 347?353 special function registers ................................................. 59 map ............................................................................. 61 spi serial clock .............................................................. 189 serial data in............................................................ 189 serial data out ......................................................... 189 slave select.............................................................. 189 spi mode.................................................................. 189 spi master/slave connection........................................... 193 spi mode master/slave connection ......................................... 193 ss ..................................................................................... 189 ssp tmr2 output for clock shift............................. 162, 163 sspov status flag .......................................................... 219 sspstat register r/w bit ............................................................. 202, 203 status bits significance and initialization condition for rcon register ............................. 35 subfwp .......................................................................... 400 sublw ............................................................................. 401 subwf............................................................................. 401 subwfb .......................................................................... 402 swapf ............................................................................. 402 t table pointer operations (table) ......................................................................... 86 tblrd .............................................................................. 403 tblwt ............................................................................. 404 time-out in various situations.................................................................... 35 time-out sequence ............................................................ 34 timer0 .............................................................................. 155 16-bit mode timer reads and writes ............................................................... 157 associated registers................................................ 157 clock source edge select (t0se bit) ......................................................... 157 clock source select (t0cs bit)......................................................... 157 operation.................................................................. 157 overflow interrupt ..................................................... 157 prescaler .................................................................. 157 switching assignment ...................................... 157 prescaler. see prescaler, timer0. timer0 and timer1 external clock requirements ........................................................... 434 timer1 .............................................................................. 159 16-bit read/write mode............................................ 161 associated registers................................................ 161 operation.................................................................. 160 oscillator........................................................... 159, 161 overflow interrupt ............................................. 159, 161 special event trigger (ccp)........................................................ 161, 171 tmr1h register....................................................... 159 tmr1l register ....................................................... 159
pic18f6585/8585/6680/8680 ds30491c-page 484 ? 2004 microchip technology inc. timer2 ............................................................................... 162 associated registers ................................................ 163 operation .................................................................. 162 postscaler. see postscaler, timer2. pr2 register............................................. 162, 173, 177 prescaler. see prescaler, timer2. ssp clock shift................................................. 162, 163 tmr2 register.......................................................... 162 tmr2 to pr2 match interrupt..................................... 162, 163, 173, 177 timer3 ............................................................................... 164 associated registers ................................................ 166 operation .................................................................. 165 oscillator ........................................................... 164, 166 overflow interrupt ............................................. 164, 166 special event trigger (ccp) ................................................................ 166 tmr3h register ....................................................... 164 tmr3l register........................................................ 164 timing diagrams a/d conversion ......................................................... 447 acknowledge sequence ........................................... 222 asynchronous reception .......................................... 241 asynchronous transmission ..................................... 238 asynchronous transmission (back to back)................................................... 238 automatic baud rate calculation ........................................................ 236 auto-wake-up bit (wue) during normal operation.............................................. 242 auto-wake-up bit (wue) during sleep ..................................................... 242 baud rate generator with clock arbitration................................................ 216 brg reset due to sda arbitration during start condition .................................................. 225 brown-out reset (bor) ............................................ 433 bus collision during a repeated start condition (case 1) ................................... 226 bus collision during a repeated start condition (case 2) ................................... 226 bus collision during a stop condition (case 1) ............................................................ 227 bus collision during a stop condition (case 2) ............................................................ 227 bus collision during start condition (scl = 0) .......................................................... 225 bus collision during start condition (sda only)......................................................... 224 bus collision for transmit and acknowledge.................................................... 223 capture/compare/pwm (all ccp modules) ............................................ 435 clko and i/o ........................................................... 429 clock synchronization .............................................. 209 clock/instruction cycle ............................................... 56 example spi master mode (cke = 0) .......................................................... 437 example spi master mode (cke = 1) .......................................................... 438 example spi slave mode (cke = 0).......................................................... 439 example spi slave mode (cke = 1).......................................................... 440 external clock (all modes except pll) ...................................................... 428 external program memory bus (16-bit mode) ...................................................... 99 first start bit ............................................................. 217 full-bridge pwm output........................................... 181 half-bridge pwm output .......................................... 180 i 2 c bus data............................................................. 441 i 2 c bus start/stop bits ............................................. 441 i 2 c master mode (7 or 10-bit transmission) ......................................... 220 i 2 c master mode (7-bit reception) ............................................... 221 i 2 c slave mode (10-bit reception, sen = 0) ........................................................... 206 i 2 c slave mode (10-bit reception, sen = 1) ........................................................... 211 i 2 c slave mode (10-bit transmission)........................................ 207 i 2 c slave mode (7-bit reception, sen = 0) ........................................................... 204 i 2 c slave mode (7-bit reception, sen = 1) ........................................................... 210 i 2 c slave mode (7-bit transmission).......................................... 205 low-voltage detect .................................................. 272 master ssp i 2 c bus data......................................... 443 master ssp i 2 c bus start/stop bits................................................... 443 parallel slave port (pic18fxx8x).................................................. 436 parallel slave port (psp) read ................................................................. 154 parallel slave port (psp) write ................................................................. 153 program memory read ............................................ 430 program memory write............................................. 431 pwm auto-shutdown (prsen = 0, auto-restart disabled) ..................................... 186 pwm auto-shutdown (prsen = 1, auto-restart enabled) ...................................... 186 pwm output ............................................................. 173 repeat start condition ............................................. 218 reset, watchdog timer (wdt), oscillator start-up timer (ost) and power-up timer (pwrt) ........................... 432 send break character sequence ............................. 243 slave mode general call address sequence (7 or 10-bit address mode) ................................................. 212 slave synchronization .............................................. 195 slow rise time (mclr tied to v dd via 1 k ? resistor) ............................................... 50 spi mode (master mode).......................................... 194 spi mode (slave mode with cke = 0) ........................................................... 196
? 2004 microchip technology inc. ds30491c-page 485 pic18f6585/8585/6680/8680 spi mode (slave mode with cke = 1) ........................................................... 196 stop condition receive or transmit mode .................................................. 222 synchronous reception (master mode, sren) ...................................... 246 synchronous transmission....................................... 244 synchronous transmission (through txen) ............................................... 245 time-out sequence on por w/pll enabled (mclr tied to v dd via 1 k ? resistor) ............................................... 50 time-out sequence on power-up (mclr not tied to v dd ) case 1 ................................................................ 49 case 2 ................................................................ 49 time-out sequence on power-up (mclr tied to v dd via 1 k ? resistor) ............................................... 49 timer0 and timer1 external clock ........................... 433 transition between timer1 and osc1 (ec with pll active, scs1 = 1) ......................... 29 transition between timer1 and osc1 (hs with pll active, scs1 = 1) ......................... 29 transition between timer1 and osc1 (hs, xt, lp) ....................................................... 28 transition between timer1 and osc1 (rc, ec) .................................................. 30 transition from osc1 to timer1 oscillator................................................. 28 usart synchronous receive (master/slave) .................................................. 445 usart synchronous transmission (master/slave) .................................................. 445 wake-up from sleep via interrupt ............................. 358 trise register pspmode bit................................................... 133, 152 tstfsz ............................................................................ 405 two-word instructions example cases........................................................... 58 txsta register brgh bit .................................................................. 233 u usart asynchronous mode ................................................. 237 12-bit break transmit and receive..................................................... 243 associated registers, receive ......................... 241 associated registers, transmit ........................ 239 auto-wake-up on sync break .......................... 242 receiver............................................................ 240 setting up 9-bit mode with address detect ......................................... 240 transmitter........................................................ 237 baud rate generator (brg) .................................... 233 associated registers........................................ 233 auto-baud rate detect..................................... 236 baud rate error, calculating............................ 233 baud rates, asynchronous modes....................................................... 234 high baud rate select (brgh bit) ............................................... 233 sampling .......................................................... 233 serial port enable (spen bit) .................................. 229 synchronous master mode....................................... 244 associated registers, reception ................................................. 246 associated registers, transmit ................................................... 245 reception ......................................................... 246 transmission .................................................... 244 synchronous slave mode......................................... 247 associated registers, receive .................................................... 248 associated registers, transmit ................................................... 247 reception ......................................................... 248 transmission .................................................... 247 usart synchronous receive requirements ........................................................... 445 usart synchronous transmission requirements ........................................................... 445 v voltage reference specifications..................................... 423 w wake-up from sleep ................................................. 345, 357 using interrupts ........................................................ 357 watchdog timer (wdt)............................................ 345, 355 associated registers................................................ 356 control register........................................................ 355 postscaler......................................................... 355, 356 programming considerations ................................... 355 rc oscillator ............................................................ 355 time-out period ........................................................ 355 wcol ............................................................................... 217 wcol status flag.................................... 217, 218, 219, 222 www, on-line support .................... ................................... 7 x xorlw ............................................................................ 405 xorwf ............................................................................ 406
pic18f6585/8585/6680/8680 ds30491c-page 486 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 487 pic18f6585/8585/6680/8680 on-line support microchip provides on-line support on the microchip world wide web site. the web site is used by microchip as a means to make files and information easily available to customers. to view the site, the user must have access to the internet and a web browser, such as netscape ? or microsoft ? internet explorer. files are also available for ftp download from our ftp site. connecting to the microchip internet web site the microchip web site is available at the following url: www.microchip.com the file transfer site is available by using an ftp service to connect to: ftp://ftp.microchip.com the web site and file transfer site provide a variety of services. users may download files for the latest development tools, data sheets, application notes, user?s guides, articles and sample programs. a vari- ety of microchip specific business information is also available, including listings of microchip sales offices, distributors and factory representatives. other data available for consideration is:  latest microchip press releases  technical support section with frequently asked questions  design tips  device errata  job postings  microchip consultant program member listing  links to other useful web sites related to microchip products  conferences for products, development systems, technical information and more  listing of seminars and events systems information and upgrade hot line the systems information and upgrade line provides system users a listing of the latest versions of all of microchip?s development systems software products. plus, this line provides information on how customers can receive the most current upgrade kits. the hot line numbers are: 1-800-755-2345 for u.s. and most of canada, and 1-480-792-7302 for the rest of the world.
pic18f6585/8585/6680/8680 ds30491c-page 488 ? 2004 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds30491c pic18f6585/8585/6680/8680 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2004 microchip technology inc. ds30491c-page 489 pic18f6585/8585/6680/8680 pic18f6585/8585/6680/8680 product identification system to order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office. part no. ? x /xx xxx pattern package temperature range device device pic18fxx8x (1) , pic18fxx8xt (2) ; v dd range 4.2v to 5.5v pic18lfxx8x (1) , pic18lfxx8xt (2) ; v dd range 2.0v to 5.5v temperature range i= -40 c to +85 c (industrial) e= -40 c to +125 c (extended) package pt = tqfp (thin quad flatpack) pattern qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18lf6680 - i/pt 301 = industrial temp., tqfp package, extended v dd limits, qtp pattern #301. b) pic18f8585 - i/pt = industrial temp., tqfp package, normal v dd limits. c) pic18f8680 - e/pt = extended temp., tqfp package, standard v dd limits. note 1: f = standard voltage range lf = extended voltage range 2: t = in tape and reel
pic18f6585/8585/6680/8680 ds30491c-page 490 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 491 pic18f6585/8585/6680/8680 notes:
pic18f6585/8585/6680/8680 ds30491c-page 492 ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. ds30491c-page 493 pic18f6585/8585/6680/8680 notes:
ds30491c-page 494 ?


▲Up To Search▲   

 
Price & Availability of PIC18F8680T-EPT

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X